Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Suppress exceptions from failing to load HostingStartup assemblies #1075

Closed
analogrelay opened this issue May 17, 2017 · 8 comments
Closed
Assignees

Comments

@analogrelay
Copy link
Contributor

When using Visual Studio to launch a project (created from the MVC template) targeting .NET Core 2.0 preview 2 dev builds, the process immediately crashes with the below exception:

Unhandled Exception: System.AggregateException: One or more errors occurred. (Startup assembly Microsoft.AspNetCore.ApplicationInsights.HostingStartup failed to execute. See the inner exception for more details.) ---> System.InvalidOperationException: Startup assembly Microsoft.AspNetCore.ApplicationInsights.HostingStartup failed to execute. See the inner exception for more details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.ApplicationInsights.HostingStartup, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, IntPtr ptrLoadContextBinder)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at NetCoreHub.Program.BuildWebHost(String[] args)
   at NetCoreHub.Program.Main(String[] args)

This is because the deps file is linked to the 2.0.0-preview1-002111-00 runtime, but the app is running in 2.0.0-preview2-25309-07 runtime. Thus the deps file isn't merged and the assembly is nowhere to be found when we try to load it.

I expect the HostingStartup to fail to load. What I don't expect is to be unable to launch my project with no idea how to fix it :). We should suppress and log these errors. I didn't do anything beyond just installing a preview runtime from https://github.com/dotnet/cli.

@Tratcher
Copy link
Member

@davidfowl

@Tratcher
Copy link
Member

By (bad) design:

if (!_options.CaptureStartupErrors)

That this fails so easily for a default VS scenario shows we need to revisit this.

@Tratcher
Copy link
Member

Offline discussion:
A) Change the design, always swallow HostingStartup exceptions, always.
B) Have VS check the runtime version before enabling the environment variables. After we fix A this will only prevent an exception from being thrown & logged. @BillHiebert

@StefanKert
Copy link

Is there any workaround available at the moment?

@analogrelay
Copy link
Contributor Author

analogrelay commented May 22, 2017

You can disable Hosting Startup entirely by setting the WebHostDefaults.PreventHostingStartupKey setting. The following code would do it: builder.UseSetting(WebHostDefaults.PreventHostingStartupKey, "true") (where builder is your WebHostBuilder)

@analogrelay
Copy link
Contributor Author

Note that this does not occur in IIS, because our default configuration suppresses this exception in IIS (that's the "By (bad) design" note above ;), we'll be suppressing the exception in all cases moving forward)

@Tratcher
Copy link
Member

@muratg please triage and assign for preview2. This is a small code change.

@analogrelay
Copy link
Contributor Author

🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants