Assembly.GetEntryAssembly is null #158

Open
jbogard opened this Issue Jan 3, 2017 · 3 comments

Projects

None yet

2 participants

@jbogard
jbogard commented Jan 3, 2017

Steps to Reproduce

Write a test that depends on Assembly.GetEntryAssembly having a meaningful value. For example all the ASP.NET Core stuff that uses DependencyContext.Default goes off of Assembly.GetEntryAssembly

Expected Behavior

It should have a value of the unit tested assembly

Actual Behavior

It is null

@plioi
Contributor
plioi commented Jan 3, 2017

Before .NET Core, I think that would have been too much of a violation of what GetEntryAssembly means. See Jon Skeet's response when similar was asked for NUnit: http://stackoverflow.com/a/26254779

For an ASP.NET Core application, though, I'll need to know more. When the application is really running, what does that method return for you? Is it the assembly that includes the Main method that in turn kicks off Kestrel? I think returning "the unit tested assembly" is potentially ambiguous, though.

@jbogard
jbogard commented Jan 3, 2017

Since ASP.NET Core is just a console app, it returns the expected ASP.NET Core project assembly.

The other alternative is for me to set the entry assembly from my unit test project. See: https://github.com/jbogard/ContosoUniversityCore/blob/master/test/ContosoUniversityCore.IntegrationTests/SliceFixture.cs#L40

File this under "things that used to work with AppDomains" because DependencyContext.Default uses GetEntryAssembly instead of AppDomain.CurrentDomain

@jbogard
jbogard commented Jan 4, 2017

FYI I opened an issue with .NET Core on this: dotnet/core-setup#1017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment