aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Startup assembly StartupBootstrapper failed to execute

Open Bazeloth opened this issue 8 years ago • 75 comments

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.

Bazeloth avatar Apr 24 '18 09:04 Bazeloth

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?

Tratcher avatar Apr 26 '18 16:04 Tratcher

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?

Bazeloth avatar Apr 30 '18 12:04 Bazeloth

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.

Bazeloth avatar Apr 30 '18 13:04 Bazeloth

@pakrym

Tratcher avatar Apr 30 '18 15:04 Tratcher

I understand you are busy, but i havent had an answer in a week. Any updates?

Bazeloth avatar May 07 '18 12:05 Bazeloth

Do you have any site extensions installed? ApplicationInsighths? What version?

pakrym avatar May 07 '18 15:05 pakrym

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?

saithis avatar May 08 '18 10:05 saithis

@clguimanMSFT any ideas?

pakrym avatar May 08 '18 16:05 pakrym

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

clguiman avatar May 08 '18 16:05 clguiman

@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.

saithis avatar May 09 '18 07:05 saithis

Did you get this variables from Process Explorer => dotnet process? Did you restart your application after installing the ApplicationInsights extension?

clguiman avatar May 09 '18 15:05 clguiman

@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 avatar May 09 '18 18:05 saithis

@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

clguiman avatar May 09 '18 19:05 clguiman

@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.

saithis avatar May 09 '18 19:05 saithis

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

clguiman avatar May 09 '18 20:05 clguiman

@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 :)

saithis avatar May 09 '18 21:05 saithis

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?

clguiman avatar May 09 '18 21:05 clguiman

@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?

Bazeloth avatar May 12 '18 11:05 Bazeloth

I tried the hostingStartupExcludeAssemblies setting now and it didn't work. I'm still getting the exception :/

saithis avatar May 14 '18 07:05 saithis

@isualize Are you deploying a self-contained application? If so - please follow the instructions here: https://github.com/aspnet/Hosting/issues/1398#issuecomment-387842930

clguiman avatar May 14 '18 15:05 clguiman