Azure Functions:启动操作期间发生主机错误无法加载文件

doo*_*man 7 asp.net-core azure-functions

我正在尝试将 Microsoft.AspNetCore.Authentication.Facebook 与 Azure 函数项目一起使用。我创建了一个完全干净的 .net core 3.1 Azure Function 项目,仅具有以下依赖项:

Microsoft.NET.Sdk.Functions 3.0.7
Microsoft.Azure.Functions.Extensions 1.0.0
Microsoft.AspNetCore.Authentication.Facebook 3.1.5
Run Code Online (Sandbox Code Playgroud)

在启动文件中我有以下代码:

 public override void Configure(IFunctionsHostBuilder builder)
 {           
     facebookOptions.AppId = Environment.GetEnvironmentVariable("Authentication:Facebook:AppId");
     facebookOptions.AppSecret = Environment.GetEnvironmentVariable("Authentication:Facebook:AppSecret");
 });
Run Code Online (Sandbox Code Playgroud)

当我运行该应用程序时,我在控制台窗口中收到以下错误:

> A host error has occurred during startup operation Could not load file
> or assembly 'Microsoft.AspNetCore.Authentication.Facebook,
> Version=3.1.5.0, Culture=neutral, PublicKeyToken='. The system cannot
> find the file specified.
Run Code Online (Sandbox Code Playgroud)

知道可能出什么问题吗?

Joe*_*Cai 1

故障排除方法有两种:

  1. 在配置文件中添加绑定重定向元素。

    <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="Microsoft.AspNetCore.Authentication.Facebook" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
         <bindingRedirect oldVersion="3.1.4" newVersion="3.1.5" />
       </dependentAssembly>
     </assemblyBinding>
    
    Run Code Online (Sandbox Code Playgroud)

    这指定使用哪个版本的程序集而不是旧版本。不一定要求在newVersion中指定更高的版本,也可以在newVersion中提供更早的版本。

  2. 更新 NuGet 包

    更新所有根项目中的 NuGet 包,然后更新引用相同包的后续引用项目(如果需要)。

欲了解更多详情,您可以参考这篇文章