Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.InvalidOperationException: AzureAppServices.HostingStartup failed to execute after deploying to Azure App service

when my release pipeline builds and tries to deploy the code to my App Service, I get this exception:

Microsoft.AspNetCore.Hosting.Diagnostics: Hosting startup assembly exception
System.InvalidOperationException: Startup assembly Microsoft.AspNetCore.AzureAppServices.HostingStartup failed to execute. See the inner exception for more details.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.AzureAppServices.HostingStartup, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.AzureAppServices.HostingStartup, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
   at System.Reflection.RuntimeAssembly.InternalLoad(NativeAssemblyNameParts* pAssemblyNameParts, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.ExecuteHostingStartups()

The project is running the .NET 8 version and all packages are updated with the Framework version, this error does not show locally and it only happens when i try to Start the App service after deploying the code.

Could it be the App Configuration section in Azure portal where maybe the Stack/Version of .NET is not up to date with the framework?

Tried to update the packages but nothing fixed it

like image 513
jber Ibra Avatar asked Oct 24 '25 07:10

jber Ibra


1 Answers

—> System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.AspNetCore.AzureAppServices.HostingStartup, Culture=neutral, PublicKeyToken=null’. The system cannot find the file specified.

This error clearly shows that the package Microsoft.AspNetCore.AzureAppServices.HostingStartup is not found in your .NET 8 Web Application.

I took the .NET Version 8 Web Application in Visual Studio 2022 and deployed to Azure App Service through Azure Pipelines. Both the build and release pipeline are successful.

Then I launched the Azure App Service, got the successful result.
Based on the Error, I have added the NuGet Package Microsoft.AspNetCore.AzureAppServices.HostingStartup to the my web application in the Visual Studio using this command:

dotnet add package Microsoft.AspNetCore.AzureAppServices.HostingStartup --version 8.0.1

Also, this NuGet package is required when you’re integrating the .NET Code Applications with the Azure App Services and this package version 8.0.1 is specific to only .NET 8 Versioned Applications as mentioned in this Official WebSite.

After adding this package, I modified the content of the Web page and pushed the changes to the App service using above configured pipelines. It works successfully:

enter image description here

Few other troubleshooting steps like:

  1. Ensure that your project dependencies are correctly configured and compatible with the .NET 8 Web Application.
  2. When you add the HostingStartup package to the application, you’ll get this type of code in your .csproj file: <PackageReference Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="x.x.x" />
  3. Even If you’re not using this package, Azure is referencing this package because of its functionality and the similar issue reported here.
like image 76
Dasari Kamali Avatar answered Oct 25 '25 23:10

Dasari Kamali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!