无法加载文件或程序集“System.ValueTuple" [英] Could not load file or assembly 'System.ValueTuple'

查看:52
本文介绍了无法加载文件或程序集“System.ValueTuple"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VS2017 项目,它编译成一个 DLL,然后由其他人编写的 EXE 调用.这两个项目都针对 .Net Framework 4.6.2.我重写了我的 DLL 方法之一以返回一个元组,并导入了关联的 NuGet 包.当我编译项目时,它在输出目录中包含 System.ValueTuple.dll,然后将其部署到其他机器,在那里我的 DLL 被加载并被 EXE 调用.但是当 EXE 尝试调用返回元组的方法时,它会崩溃:

I've got a VS2017 project that compiles to a DLL which is then called by an EXE written by someone else. Both projects target .Net Framework 4.6.2. I rewrote one of my DLL methods to return a tuple and also imported the associated NuGet package. When I compile the project it includes System.ValueTuple.dll in the output directory which is then deployed to other machines where my DLL is loaded and called by the EXE. But when the EXE attempts to call the method that returns a tuple it crashes:

意外错误无法加载文件或程序集System.ValueTuple,版本=4.0.1.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51"或其依赖项之一.系统找不到指定的文件.

Unexpected Error Could not load file or assembly 'System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

我不明白为什么找不到该文件,因为它与我的 DLL 位于同一文件夹中.显然 MS 没有在 .Net Framework 4.6.2 中包含这个程序集.

I'm not understanding why it's not finding the file since it's in the same folder as my DLL. Apparently MS did not include this assembly in .Net Framework 4.6.2.

请注意,我的 DLL 是使用 machine.config 文件在 Windows 中注册的.我猜如果我也将 System.ValueTuple.dll 添加到这个文件中,它会起作用(还没有尝试过,不确定这是最好的方法,尤其是长期的.)除了等待 4.6 之外,还有更好的方法吗?.3 并希望它包含此程序集?

Note that my DLL is registered in Windows using a machine.config file. I'm guessing that if I also add System.ValueTuple.dll to this file it will work (haven't tried yet and not sure this is the best approach, especially long term.) Is there a better way, besides waiting for 4.6.3 and hoping it includes this assembly?

推荐答案

我通过在我计算机的 machine.config 文件中注册 System.ValueTuple(以及我自己的 DLL,它已经在那里注册)解决了这个问题.我并不特别喜欢这种方法,因为它依赖于随时可能更改的 DLL 版本.希望 MS 会将这个程序集添加到 .Net Framework 的下一个版本中.

I resolved this issue by registering System.ValueTuple in my computer's machine.config file (along with my own DLL which was already registered there). I don't particularly like this approach though since it's dependent upon the DLL version which is subject to change at any time. Hopefully MS will just add this assembly to the next version of the .Net Framework.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" />
    <bindingRedirect oldVersion="0.0.0.0-99.99.99.99" newVersion="4.0.1.0" />
    <codeBase version="4.0.1.0" href="e:execSystem.ValueTuple.dll" />
  </dependentAssembly>
  ...
</assemblyBinding>
</runtime>

这篇关于无法加载文件或程序集“System.ValueTuple"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆