Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法加载文件或程序集';System.Runtime.InteropServices.RuntimeInformation_C#_Azure_Azure Application Insights_Webjob_Interopservices - Fatal编程技术网

C# 无法加载文件或程序集';System.Runtime.InteropServices.RuntimeInformation

C# 无法加载文件或程序集';System.Runtime.InteropServices.RuntimeInformation,c#,azure,azure-application-insights,webjob,interopservices,C#,Azure,Azure Application Insights,Webjob,Interopservices,每当我尝试使用ApplicationInsight和EntityFramework运行webjob项目时,都会出现此错误 System.IO.FileLoadException:'无法加载文件或程序集 'System.Runtime.InteropServices.RuntimeInformation,版本=0.0.0.0, 区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'或其 依赖关系。定位程序集的清单定义不正确 匹配程序集引用。(HRESULT的例外:0x801

每当我尝试使用ApplicationInsight和EntityFramework运行webjob项目时,都会出现此错误

System.IO.FileLoadException:'无法加载文件或程序集 'System.Runtime.InteropServices.RuntimeInformation,版本=0.0.0.0, 区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'或其 依赖关系。定位程序集的清单定义不正确 匹配程序集引用。(HRESULT的例外:0x8013100)'

我已经安装了以下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>


(对于Windows服务,在我的例子中是app.config。)我的项目仅间接依赖于System.Runtime.InteropServices.RuntimeInformation。它是我导入的NuGet软件包的依赖项。

如果您已将项目的.NET运行时版本从4.7.1之前的版本更新到4.7.1或更高版本,然后卸载NuGet软件包,请删除/注释掉App.config部分(如果它仍然存在),然后从框架中重新添加引用。它是从4.7.1开始的框架,在此之前,您必须添加一个Nuget包


[编辑]。。。根据Michael在上面的评论,我在living memory之前进行了升级。

这似乎有点倒退,但我最近也遇到了这个问题,我安装的NuGet软件包已经将它的DependentSambly(以及其他几个软件包)添加到了web.config中。在我的例子中,去掉新添加的dependentAssembly条目修复了问题。只是想试试别的。@dwilliss你的解决方案对我有用。感谢您指出这一点。为什么这样做:如果您查看VisualStudio部署的程序集版本,在我的例子中是版本4.0.1。就VisualStudio所知,您的代码只显式地引用(直接或间接地)版本4.0.1,所以这就是复制到输出目录中的全部内容。我想如果它根本没有被复制,那就表明它包含在框架中。如果使用(Add BIndingRedirect)重新生成绑定重定向,它不会将该重定向添加到4.0.2,这证实了它不是必需的,在这种情况下实际上是有害的。或者,添加对4.0.2.Worked for me版本的真实引用-这也是app.config.Related的相关解决方案,这解释了为什么(在什么情况下)删除绑定重定向可能会有所帮助。完整的建议列表-非常感谢。注释了web.config中的代码,效果非常好。主要是添加绑定重定向解决了dll地狱问题。这一次,移除它解决了问题。如果没有这个答案,我将不得不花费数小时来解决这个问题。值得一提的是,这个dll需要.net 4.6.1或更高版本