繁体   English   中英

无法加载文件或程序集或其依赖项之一。

[英]Could not load file or assembly or one of its dependencies.

我知道这个问题很多,但是我尝试了所有解决方案,但没有成功!

在调试模式下运行时,这是错误:

System.IO.FileLoadException:'无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。 找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)

我尝试删除solution所有projects所有binobj文件夹。 还删除了Packages文件夹。

还删除了所有配置文件中的此项:

<dependentAssembly>
    <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>

还在上面的代码newVersion值更改为4.0.0.0但绝不喜欢!

当我卸载项目并对其进行编辑时,我看到以下行:

<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>

我怎么解决这个问题? 提前致谢。

可能为时已晚,但是在使用.net 4.6.2的一台旧版构建服务器上,MongoDB驱动程序(从2.5升级到2.7)遇到了类似的问题。 奇怪的是,使用Visual Studio构建时,它可以在本地计算机上工作。 问题在于NuGet本身,以及在软件包更新期间添加的错误程序集绑定。 我们必须手动检查正确的程序集版本并覆盖app.config中的值。

确保通过在目标计算机上添加以下注册表项来激活详细的日志记录:HKLM \\ Software \\ Microsoft \\ Fusion> EnableLog(DWORD)设置为1

然后,您可以获得更详细的信息,确切的DLL会引起问题。

以下PowerShell命令可以帮助找到正确的程序集版本。 例如,InteropServices:

[System.Reflection.Assembly]::LoadFrom("C:\path_to_your_release_folder\System.Runtime.InteropServices.RuntimeInformation.dll").GetName().Version

在我们的例子中是:

Major  Minor  Build  Revision
-----  -----  -----  -------- 
4      0      1      0

在app.config中,NuGet编写了4.0.2.0,因此我们将其更改为4.0.1.0:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>

一切都按照预期自动进行了。

因此,确保使用哪种绑定的唯一方法是使用上述方法自己检查版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM