在我的 azure 函数应用项目中,我收到一个程序集未找到运行时错误 Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0。但是,该程序集包含在我从 NuGet 安装的多个包中。
Visual Studio:2019 目标框架:netcoreapp3.1 Azure Functions 版本:v3
包含 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0) 的已安装包:
错误: 启动操作期间发生主机错误...无法加载文件或程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。
无效的修复尝试: 从 NuGet 安装了 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0),但错误仍然存在。
在类似的问题Microsoft.Extensions #2931和StackOverflow question 之后,我在项目文件中添加了以下内容。
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我也跟着一篇文章的建议。安装 Microsoft.Azure.Functions.Extensions 后,错误仍然存在。
我还遵循了另一个建议,并将以下内容添加到我的项目文件中。但是,错误仍然存在。
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions"
publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="5.0.0.0"
newVersion="5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>
Run Code Online (Sandbox Code Playgroud)
我尝试了ASP.NET Core 公告的问题#401 中建议的解决方法:引用未能在我的应用程序中显式加载的程序集的包。但是,错误仍然存在。
使用 ILSpy,我发现我从 NuGet 安装的 Microsoft.Azure.Functions.Extensions …