无法加载文件或程序集'System.ValueTuple'

时间:2021-08-14 16:05:39

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:

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

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.

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

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在同一文件夹中。显然MS没有在.Net Framework 4.6.2中包含此程序集。

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?

请注意,我的DLL使用machine.config文件在Windows中注册。我猜测,如果我还将System.ValueTuple.dll添加到此文件中它将起作用(尚未尝试,并且不确定这是最好的方法,特别是长期。)除了等待4.6之外还有更好的方法吗? .3并希望它包括这个组件?

4 个解决方案

#1


10  

FWIW, I had this issue on my testing project using Moq. Someone had set the project to .NET 4.7, but I was on 4.6.2. Not wanting to move to 4.7 yet, the solution was to downgrade the version to Moq 4.7.145. The System.ValueTuple v 4.3.1 worked together with it.

FWIW,我在使用Moq的测试项目中遇到了这个问题。有人把项目设置为.NET 4.7,但我在4.6.2。不想转向4.7,解决方案是将版本降级为Moq 4.7.145。 System.ValueTuple v 4.3.1与它一起工作。

#2


8  

I faced the same exception when there was a nuget package version mismatch. (In the DLL was 4.3.1 used while in the main program 4.3.0.) I have resolved the issue by upgrading the packages to the same version... Checking and unifying the package versions could hopefully help you as well.

当nuget包版本不匹配时,我遇到了同样的异常。 (在主程序4.3.0中使用的DLL是4.3.1。)我已经通过将软件包升级到相同的版本来解决了这个问题...检查和统一软件包版本也可能对你有所帮助。

#3


6  

I just had this issue myself. Not on Localhost while developing, but only on production server. In the end it turned out to be some sort of conflict between .Net Framework 4.6.1 and me having System.ValueTuple installed from Nuget in version 4.5.0.

我自己就是这个问题。在开发时不在Localhost上,但仅在生产服务器上。最后,结果证明.Net Framework 4.6.1与我之间存在某种冲突,在4.5.0版本中从Nuget安装了System.ValueTuple。

The solution turned out to be, to downgrade the System.ValueTuple Nuget package to 4.3.0. Then it worked, like nothing had ever been an issue.

解决方案原来是将System.ValueTuple Nuget软件包降级到4.3.0。然后它起作用,就像从来没有任何问题一样。

I suspect that this only happened on production server, cause of a different version of .net framework installed.

我怀疑这只发生在生产服务器上,导致安装了不同版本的.net框架。

#4


2  

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.

我通过在我的计算机的machine.config文件中注册System.ValueTuple来解决这个问题(以及我已经在那里注册的我自己的DLL)。我并不特别喜欢这种方法,因为它依赖于DLL版本,它随时都可能发生变化。希望MS只将这个程序集添加到下一版本的.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:\exec\System.ValueTuple.dll" />
  </dependentAssembly>
  ...
</assemblyBinding>
</runtime>

#1


10  

FWIW, I had this issue on my testing project using Moq. Someone had set the project to .NET 4.7, but I was on 4.6.2. Not wanting to move to 4.7 yet, the solution was to downgrade the version to Moq 4.7.145. The System.ValueTuple v 4.3.1 worked together with it.

FWIW,我在使用Moq的测试项目中遇到了这个问题。有人把项目设置为.NET 4.7,但我在4.6.2。不想转向4.7,解决方案是将版本降级为Moq 4.7.145。 System.ValueTuple v 4.3.1与它一起工作。

#2


8  

I faced the same exception when there was a nuget package version mismatch. (In the DLL was 4.3.1 used while in the main program 4.3.0.) I have resolved the issue by upgrading the packages to the same version... Checking and unifying the package versions could hopefully help you as well.

当nuget包版本不匹配时,我遇到了同样的异常。 (在主程序4.3.0中使用的DLL是4.3.1。)我已经通过将软件包升级到相同的版本来解决了这个问题...检查和统一软件包版本也可能对你有所帮助。

#3


6  

I just had this issue myself. Not on Localhost while developing, but only on production server. In the end it turned out to be some sort of conflict between .Net Framework 4.6.1 and me having System.ValueTuple installed from Nuget in version 4.5.0.

我自己就是这个问题。在开发时不在Localhost上,但仅在生产服务器上。最后,结果证明.Net Framework 4.6.1与我之间存在某种冲突,在4.5.0版本中从Nuget安装了System.ValueTuple。

The solution turned out to be, to downgrade the System.ValueTuple Nuget package to 4.3.0. Then it worked, like nothing had ever been an issue.

解决方案原来是将System.ValueTuple Nuget软件包降级到4.3.0。然后它起作用,就像从来没有任何问题一样。

I suspect that this only happened on production server, cause of a different version of .net framework installed.

我怀疑这只发生在生产服务器上,导致安装了不同版本的.net框架。

#4


2  

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.

我通过在我的计算机的machine.config文件中注册System.ValueTuple来解决这个问题(以及我已经在那里注册的我自己的DLL)。我并不特别喜欢这种方法,因为它依赖于DLL版本,它随时都可能发生变化。希望MS只将这个程序集添加到下一版本的.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:\exec\System.ValueTuple.dll" />
  </dependentAssembly>
  ...
</assemblyBinding>
</runtime>