System.InvalidOperationException:AzureAppServices.HostingStartup 部署到 Azure 应用服务后无法执行

问题描述 投票:0回答:1

当我的发布管道构建并尝试将代码部署到我的应用服务时,我收到此异常:

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()

该项目正在运行 .NET 8 版本,并且所有包均已使用 Framework 版本更新,此错误不会在本地显示,仅当我在部署代码后尝试启动应用程序服务时才会发生。

是否是 Azure 门户中的应用程序配置部分,其中 .NET 的堆栈/版本可能与框架不同步?

尝试更新软件包但没有解决问题

.net azure azure-devops azure-web-app-service nuget-package
1个回答
1
投票

—> System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.AspNetCore.AzureAppServices.HostingStartup,Culture=neutral,PublicKeyToken=null”。系统找不到指定的文件。

此错误清楚地表明在您的 .NET 8 Web 应用程序中找不到包

Microsoft.AspNetCore.AzureAppServices.HostingStartup

我在 Visual Studio 2022 中使用了 .NET 版本 8 Web 应用程序,并通过 Azure Pipelines 部署到 Azure 应用服务。构建和发布管道均成功。

然后我启动了Azure App Service,得到了成功的结果。
根据错误,我已使用以下命令将 NuGet Package

Microsoft.AspNetCore.AzureAppServices.HostingStartup
添加到 Visual Studio 中的 Web 应用程序:

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

此外,当您将 .NET 代码应用程序与 Azure 应用服务集成时,需要此 NuGet 包,并且此包版本

8.0.1
仅特定于 .NET 8 版本应用程序,如本官方网站中所述。

添加此包后,我修改了网页内容,并使用上面配置的管道将更改推送到应用程序服务。运行成功:

enter image description here

其他一些故障排除步骤,例如:

  1. 确保您的项目依赖项已正确配置并与 .NET 8 Web 应用程序兼容。
  2. 当您将
    HostingStartup
    包添加到应用程序时,您将在
    .csproj
    文件中获得此类代码:
    <PackageReference Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="x.x.x" />
  3. 即使您没有使用此包,Azure 也会引用此包,因为它的功能和此处报告的类似问题。
© www.soinside.com 2019 - 2024. All rights reserved.