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
—> 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:
Few other troubleshooting steps like:
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" />