Startup assembly StartupBootstrapper failed to execute
Im getting this error in my logs currently:
2018-04-23 18:10:25.818 +00:00 [Fatal] Hosting startup assembly exception System.InvalidOperationException: Startup assembly StartupBootstrapper failed to execute. See the inner exception for more details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'StartupBootstrapper, 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 ---
Im using the following version of microsoft.aspnetcore: .nuget\packages\microsoft.aspnetcore\2.0.1\lib\netstandard2.0\Microsoft.AspNetCore.dll
Am i missing something or is this a known bug? Im hosting this in an Azure App Service.
We're going to need more than that, Can you share a repro app?
Any call to Assembly.Load is suspect. What are you trying to do?
Creating a repro app will take some time as this is (company) production code, but in essentially we're just doing this:
`public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}`
Which in turn executes this:
`// Execute the hosting startup assemblies
foreach (var assemblyName in _options.GetFinalHostingStartupAssemblies().Distinct(StringComparer.OrdinalIgnoreCase))
{
try
{
var assembly = Assembly.Load(new AssemblyName(assemblyName));
foreach (var attribute in assembly.GetCustomAttributes<HostingStartupAttribute>())
{
var hostingStartup = (IHostingStartup)Activator.CreateInstance(attribute.HostingStartupType);
hostingStartup.Configure(this);
}
}
catch (Exception ex)
{
// Capture any errors that happen during startup
exceptions.Add(new InvalidOperationException($"Startup assembly {assemblyName} failed to execute. See the inner exception for more details.", ex));
}
}`
Im not sure where this StartupBootstrapper is coming from. Could you give me a hint to be able to look this up?
To be honest i think it's related to https://github.com/aspnet/Hosting/issues/1246
I added this reference to my project a while ago:
<PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.2-preview2-final" />
Before that i noticed the same error, but it mentioned the Azure Key Vault dll could not be found.
@pakrym
I understand you are busy, but i havent had an answer in a week. Any updates?
Do you have any site extensions installed? ApplicationInsighths? What version?
We got the same exception in our app. After removing the ApplicationInsights site extension from the deployment script, the exception vanished. Any idea how to fix this?
@clguimanMSFT any ideas?
StartupBootstrapper comes from the "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES" environment variable which is set by the ApplicationInsights site extension. Is the code running on netcore 2.0 or 2.1? If it's 2.0 please share the content of the following env variables: DOTNET_SHARED_STORE & DOTNET_ADDITIONAL_DEPS
@clguimanMSFT We use asp net core 2.0 with .net framework:
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<Platforms>AnyCPU;x64</Platforms>
The only DOTNET_... environment variables, that Kudu shows are: DOTNET_CLI_TELEMETRY_PROFILE = AzureKudu DOTNET_HOSTING_OPTIMIZATION_CACHE = D:\DotNetCache DOTNET_SKIP_FIRST_TIME_EXPERIENCE = true Also it doesnt show ASPNETCORE_HOSTINGSTARTUPASSEMBLIES.
Did you get this variables from Process Explorer => dotnet process? Did you restart your application after installing the ApplicationInsights extension?
@clguimanMSFT I got it from Environment -> environment variables. I didn't know that these are different from the ones under Process Explorer.
In Process Explorer I have these:
- w3wp.exe:
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES | StartupBootstrapper
DOTNET_ADDITIONAL_DEPS | D:\Program Files (x86)\dotnet\additionalDeps\Microsoft.AspNetCore.ApplicationInsights.HostingStartup\;D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\2.5.6\core\additionalDeps
DOTNET_SHARED_STORE | D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\2.5.6\core\store\
- SnapshotHolder_x86.exe:
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES | StartupBootstrapper
DOTNET_ADDITIONAL_DEPS | D:\Program Files (x86)\dotnet\additionalDeps\Microsoft.AspNetCore.ApplicationInsights.HostingStartup\;D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\2.5.6\core\additionalDeps
DOTNET_SHARED_STORE | D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\2.5.6\core\store\
- My Api exe without any environment variables
Edit: Yes, I did restart the application afterwards.
@saithis You deployed a self-contained dotnetcore application? We don't support auto enablement of ApplicationInsights & SnapshotCollector for those. You'll need to add these packages as nuget dependencies to your project.
You can find more information here:
- https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-core
- https://docs.microsoft.com/en-us/azure/application-insights/app-insights-snapshot-debugger
@clguimanMSFT Yes, it is a self-contained aspnetcore application running on .net framework 4.6.1. We have installed the Microsoft.ApplicationInsights.AspNetCore as a nuget package, but also installed the site extension to get the sql queries in the logs.
I will try installing the snapshot debugger nuget package when I get back to work on monday, thanks.
You can still install the extension, but your app shouldn't try and blindly load HostingStartup assemblies. If there's some reason you need to do that, you can just ignore the exception for StartupBootstrapper or explicitly remove that assembly from the list
@clguimanMSFT Its the asp net core code that "blindly loads HostingStartup assemblies" in WebHostBuilder.Build(). But setting "hostingStartupExcludeAssemblies" to "StartupBootstrapper" should exclude that assembly then, right? Can you tell me what the StartupBootstrapper assembly is for? Is there a negative effect for self-contained aspnetcore applications, when it can't be loaded and I just exclude it?
Thanks for the help so far :)
The StartupBootstrapper assembly is part of ApplicationInsights site extension and it's used to inject ApplicationInsights assemblies in Azure Web Apps. This code detects if ApplicationInsights is already present in the process and will back-off if necessary. @pakrym can you please help @saithis with the HostingStartup questions?
@clguimanMSFT We are using Azure App Services and run the same configuration as @saithis. We are using .net core 2.0 and application insights 2.4.0 and get the same exception in our logs.
Under process i couldnt find anything other then w3wp. What is the next step to resolve this problem?
I tried the hostingStartupExcludeAssemblies setting now and it didn't work. I'm still getting the exception :/
@isualize Are you deploying a self-contained application? If so - please follow the instructions here: https://github.com/aspnet/Hosting/issues/1398#issuecomment-387842930