每当我尝试运行具有应用程序洞察力和实体框架的webjob项目时,我都会收到此错误。
System.IO.FileLoadException:'无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)'
我安装了以下nuget包
Microsoft.Azure.WebJobs.Logging.ApplicationInsights版本2.1.0-beta4
Microsoft.Extensions.Logging版本2.0.0
Microsoft.Extensions.Logging.Console版本2.0.0。
这一切都适用于一个新的Visual Studio 2017 webjob项目,当我尝试包含现有的代码库时,主要使用实体框架,我得到了这个错误。当我查看工作中的引用时,我没有System.Runtime.InteropServices.RuntimeInformation,但它已经添加到具有实体框架的项目中。它似乎是.net标准的一部分,但为什么我的新控制台应用程序不需要.net标准!
我不确定它为什么寻找版本0.0.0.0,因为我的版本是4.0.2.0
我也尝试将其添加到项目文件中,但这不起作用。
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
任何帮助将不胜感激
非常感谢
你能错过配置文件中加载的程序集吗?确保在web.config中有类似于以下内容的内容。 NuGet通常会这样做,但也许它没有,它不知道要加载什么
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
确认dwilliss上面的评论也对我有用。解决方案是摆脱:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
(就我的情况而言,来自app.config,适用于Windows服务。)我的项目仅与System.Runtime.InteropServices.RuntimeInformation间接依赖。它是我导入的NuGet包的依赖项。