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

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

无法加载文件或程序集系统。ValueTuple,Version = 4.0.1.0,Culture = 材质,PublicKeyToken = cc7b13ffcd2ddd51’或其依赖项之一。系统找不到指定的文件。

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

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

114930 次浏览

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:\exec\System.ValueTuple.dll" />
</dependentAssembly>
...
</assemblyBinding>
</runtime>

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.

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.

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.

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.

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

ok this feels completely wrong but I cut

  <dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>

This out of my web.config for the main application.

I was really just seeing what happened to see if there was an underlying dependency or something, not expecting it to run. It just carried on working, all the new functions I have added in the last few days still work.

I had this same issue with an AutoMapper 8.0.0.0 dependency on version 4.5 after upgrading from .NET 4.5.1 to 4.6.1. Reinstalling the automapper nuget package worked for me.

My issue was that I was developing against 4.6.1, but releasing on 4.7.2. Luckily I don't mind which .Net framework this project was built for, so I installed 4.7.2 on my developer instance, then upgraded all the Nuget packages.

(Using SQLite on AWS EC2)

Solved it by installing .NET Framework 4.7.2 Runtime on the machine the error occurred on. Simple and no need to add bindingRedirect or downgrading NuGet packages.

https://dotnet.microsoft.com/download/dotnet-framework/net472

I hade the same issue, i solve the probleme by changing the target framwork of the project to .Net Framwork 4.7.1.

System.ValueTuple now supports .NET Framework 4.7

IF your are unable to update .Net Framework to the latest version, then downgrade Package: Microsoft.Net.Compilers to the version up to 2.10. This solved the issue in my case.

I had a library which used a newer version of the System.ValueTuple NuGet package. I then used another library which caused me to use the older version installed in the main project for the first time. That caused this exception to reveal itself. Updating both (or, converging them in any way - downgrading both is fine too) - fixed the issue.

In my solution I found 2 different trouble maker. Either in the App.config or Web.config file:

  1. Version mismatch: The version installed via NuGet did not match the version in the config file. Solution: Change the version manually in the .config file.

  2. Duplicate entries: I found duplicate entries for ValueTuple. In my case one for 4.0.3.0 and another one for 4.5.0. Removing the older entry solved the issue.

In another case I managed to fix the issue by removing unneeded references and getting rid of the ValueTuple NuGet package altogether.

I resolved this issue by installing System.ValueTuple from nuget. It was not previously installed but I guess RestSharp or another library is using it.

So this got it fixed.

In my case I think something delete this dll from project and framework folders, maybe during installing something it flied; so my project during debugging couldn't find that dll and throw that error. I installed

Install-Package System.ValueTuple -Version 4.5.0

Package and than everything worked again. Before doing further complicated solutions as described above answers may installing ValueTuple package works for you.

If you have AutoMapper version 8.0 or lower referenced in any of your projects, it's possibly the source of the issue. See this github issue for more information.

If I understand correctly, the issue is that .NET Framework versions below version 4.7 did not have System.ValueTuple shipped with them by default, so AutoMapper was using a NuGet package reference for the assembly since it has build targets for Framework versions below 4.7. This caused some funky Microsoft stuff.

The easiest solution is to upgrade your AutoMapper references to version 8.1.0 or newer, where they have scraped all uses of the assembly from their codebase and removed the dependency.

Adding on to Robin's answer for just changing the Web.config. I was able to get away with only commenting out the binding redirect tag.

<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<!--<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />-->
</dependentAssembly>

This got rid of the error for me.

I experienced the same error "Could not load file or assembly System.ValueTuple.dll..." on my Windows Server 2016. However, the site worked fine on my dev machine.

My solution was simple, I grabbed this dll from my dev machine and dropped it in the site's "bin" folder on the server. It worked.

Solved it by installing VS 2019.

I hope this isn't thread necromancy, because this is still the #1 searched thing on Google. None of the other comments worked for me sadly.

We resolved this issue recently after over a year with this problem. The issue was a package called 'GitVersion'. So for anybody who is still struggling with this and looking around the forums I know quite a few are; I would advise you check your packages and see what their dependencies are.

Fixed this by switching the Copy Local flag on my reference to System.ValueTuple from copy always to none. (It was on an assembly containing tests).

Right clicking References and choosing "Migrate packages.config to PackageReference..." solved the problem for me (and other similar issues).

I had this issue in a Visual Studio setup/installer project. For some reason my project had multiple instances of System.ValueTuple.dll:

tuplemania

Deleting the extras at the bottom made the setup project build. For one of them I had to right click, choose "Find In Editor", and delete from the resulting window. Otherwise I got a cryptic error (something to the effect of "the parameter is incorrect" if I recall correctly).