每当我尝试使用应用程序洞察和实体框架运行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>
非常感谢任何帮助
非常感谢
答案 0 :(得分:12)
确认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>
(对于Windows服务,对于我来说是来自app.config。)我的项目仅间接依赖于System.Runtime.InteropServices.RuntimeInformation。这是我导入的NuGet包的依赖项。
答案 1 :(得分:10)
你能错过配置文件中加载的程序集吗?确保在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>
答案 2 :(得分:3)
如果已将项目的.NET运行时版本从4.7.1之前的版本更新为4.7.1或更高版本,然后卸载Nuget程序包,请删除/注释掉App.config部分(如果保留),然后重新添加框架中的参考。从4.7.1开始,它是在框架中的,在此之前,您必须添加Nuget程序包。
[edit] ...根据我上面迈克尔在生活记忆中提出的评论。