Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Tests for not calling AssemblyResolve event for CoreLib resources - #22552

Merged
kouvel merged 6 commits into
dotnet:masterfrom
kouvel:LoadFromFixFx
Jul 25, 2017
Merged

kouvel merged 6 commits into
dotnet:masterfrom
kouvel:LoadFromFixFx

Conversation

@kouvel

@kouvel kouvel commented Jul 24, 2017 •

Copy link
Copy Markdown

Part of fix for dotnet/coreclr#12668
Depends on dotnet/coreclr#12999

return typeof(AppDomainTests).Assembly;
};

CultureInfo previousUICulture = CultureInfo.CurrentUICulture;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @tarekgh previously told me that this pattern is problematic for UWP, as UWP doesn't have the notion of per-thread culture and thus changing the thread's culture actually ends up changing the process' culture. You might need to either restrict the platforms on which this test runs, or use RemoteInvoke to move it out-of-proc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we should use RemoteInvoke for this test.


[Fact]
public void AssemblyResolve_LoadFromHandlerChecksForNullRequestingAssembly()
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to test the right thing on Unix?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I'll see how to fix

{
Assert.ThrowsAny<Exception>(() => Assembly.LoadFrom(@"nonexistent.dll"));

CultureInfo previousUICulture = CultureInfo.CurrentUICulture;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use RemoteInvoke for this test too. thanks.

[Fact]
[ActiveIssue("https://github.com/dotnet/corefx/issues/22555", TargetFrameworkMonikers.Uap)]
public void AssemblyResolve_LoadFromHandlerChecksForNullRequestingAssembly()
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we expect a specific exception to test against? (e.g. FileNotFound)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this test exercises the fix - I think it will be passing even without the fix.

To exercise the fix, the file has to exist so that LoadFrom starts running at least.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadFrom registers the AssemblyResolve event handler, and runs up to the last line where it throws FileNotFoundException. The handler gets called later and throws ArgumentNullException because the requesting assembly is null.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok

}).Dispose();
}

[Fact]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this test will fail on Uap-Aot? I am asking because of TargetFrameworkMonikers.Uap will skip the test for both aot and none aot

@tarekgh tarekgh Jul 24, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please have this test run inside the remote invoke. I prefer setting current culture in isolation in general. Also, this will simplify the code so you don't have to do finally block to rest it back

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to unblock the CoreCLR fix, I'll be looking at the that issue for uap next

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the tests should pass on uap so I'll disable only for uapaot against that issue, after switching to RemoteInvoke

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, does this change need to be ported to .Net Native (I mean corert)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please track it to make sure we'll not miss it there. Thanks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the same issue linked in the attribute

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like AssemblyResolve is not raised at all in CoreRT and Assembly.LoadFrom is not supported. Feels to me like both are by design to disallow changing assembly resolution. @jkotas, does that sound right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And because it's only aot I guess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

}

[Fact]
[ActiveIssue("https://github.com/dotnet/corefx/issues/22555", TargetFrameworkMonikers.UapAot)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test still exercising the LoadFrom handler? I do not think that the LoadFrom handler is going to be called in this test - given the other half of the fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other half of the fix prevents the handler from running. I'll see if I can find a way to exercise the handler.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a way to exercise the handler to test this particular issue after the other half of the fix. The requesting assembly is null only for domain-neutral assemblies, which I guess is only CoreLib, and the recursion issue following the exception from the AssemblyResolve handler only happens if it's trying to resolve CoreLib resources.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Delete the test then?

I suspect that there are other rare situations where the requesting assembly is null that we cannot think of, so I would keep the null check in the LoadFrom handler.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will remove

Assert.Throws<NullReferenceException>(() => ((string)null).Contains("a"));
Assert.False(assemblyResolveHandlerCalled);
}
finally

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to restore the current culture. you may get rid of the whole previousUICulture code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment apply to the other test case too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't hurt to keep it, I'd rather have the test undo any external changes it made even if it has no effect

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will not hurt but it is really not needed.

@kouvel

kouvel commented Jul 25, 2017

Copy link
Copy Markdown
Author

@dotnet-bot test this please

@kouvel

kouvel commented Jul 25, 2017

Copy link
Copy Markdown
Author

Is this good to merge?

@tarekgh

tarekgh commented Jul 25, 2017

Copy link
Copy Markdown
Member

Looks it passed all tests so I think it is good to go. Did we got coreclr fix in corefx?

@kouvel

kouvel commented Jul 25, 2017

Copy link
Copy Markdown
Author

Yea the fix is there now, thanks!

@kouvel
kouvel merged commit 183a04e into dotnet:master Jul 25, 2017
@kouvel
kouvel deleted the LoadFromFixFx branch July 25, 2017 18:44
@karelz karelz modified the milestone: 2.1.0 Aug 14, 2017
danmoseley pushed a commit that referenced this pull request Aug 21, 2017
…2552) (#22553)

Tests for not calling AssemblyResolve event for CoreLib resources

Part of fix for #12668
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…tnet/corefx#22552)

Tests for not calling AssemblyResolve event for CoreLib resources

Part of fix for dotnet/corefx#12668

Commit migrated from dotnet/corefx@183a04e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants