简体   繁体   English

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

[英]Could not load file or assembly 'System.ValueTuple'

I've got a VS2017 project that compiles to a DLL which is then called by an EXE written by someone else.我有一个编译为 DLL 的 VS2017 项目,然后由其他人编写的 EXE 调用它。 Both projects target.Net Framework 4.6.2.这两个项目都以 .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.我重写了我的 DLL 方法之一以返回一个元组,并且还导入了关联的 NuGet package。当我编译该项目时,它在 output 目录中包含 System.ValueTuple.dll,然后将其部署到名为 8872976 的其他机器上执行文件。 But when the EXE attempts to call the method that returns a tuple it crashes:但是,当 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.意外错误无法加载文件或程序集“System.ValueTuple,Version=4.0.1.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”或其依赖项之一。 The system cannot find the file specified.该系统找不到指定的文件。

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

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.这是我的 web.config 主应用程序。

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 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.最后,结果证明 .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 .结果证明,解决方案将 System.ValueTuple Nuget 包降级到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.我怀疑这仅发生在生产服务器上,原因是安装了不同版本的 .net 框架。

Solved it by installing .NET Framework 4.7.2 Runtime on the machine the error occurred on.通过在发生错误的机器上安装.NET Framework 4.7.2 Runtime解决了这个问题。 Simple and no need to add bindingRedirect or downgrading NuGet packages.简单,无需添加bindingRedirect或降级 NuGet 包。

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

FWIW, I had this issue on my testing project using Moq. FWIW,我在使用 Moq 的测试项目中遇到了这个问题。 Someone had set the project to .NET 4.7, but I was on 4.6.2.有人将项目设置为 .NET 4.7,但我使用的是 4.6.2。 Not wanting to move to 4.7 yet, the solution was to downgrade the version to Moq 4.7.145.还不想迁移到 4.7,解决方案是将版本降级到 Moq 4.7.145。 The System.ValueTuple v 4.3.1 worked together with it. System.ValueTuple v 4.3.1 与它一起工作。

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).我通过在我的计算机的 machine.config 文件中注册 System.ValueTuple 解决了这个问题(以及我自己的 DLL,它已经在那里注册了)。 I don't particularly like this approach though since it's dependent upon the DLL version which is subject to change at any time.我并不特别喜欢这种方法,因为它依赖于随时可能更改的 DLL 版本。 Hopefully MS will just add this assembly to the next version of the .Net Framework.希望 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>

I faced the same exception when there was a nuget package version mismatch.当 nuget 包版本不匹配时,我遇到了同样的异常。 (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. (在 DLL 中使用的是 4.3.1,而在主程序 4.3.0 中。)我已经通过将包升级到相同版本解决了这个问题......检查和统一包版本也有望对您有所帮助。

Adding on to Robin's answer for just changing the Web.config.添加到 Robin 的仅更改 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.这为我消除了错误。

My issue was that I was developing against 4.6.1, but releasing on 4.7.2.我的问题是我是针对 4.6.1 开发的,但在 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.幸运的是,我不介意这个项目是为哪个 .Net 框架构建的,所以我在我的开发人员实例上安装了 4.7.2,然后升级了所有的 Nuget 包。

( Using SQLite on AWS EC2 ) 在 AWS EC2 上使用 SQLite

I hade the same issue, i solve the probleme by changing the target framwork of the project to .Net Framwork 4.7.1.我遇到了同样的问题,我通过将项目的目标框架更改为 .Net 框架 4.7.1 来解决问题。

System.ValueTuple now supports .NET Framework 4.7 System.ValueTuple 现在支持 .NET Framework 4.7

In my solution I found 2 different trouble maker.在我的解决方案中,我发现了 2 个不同的麻烦制造者。 Either in the App.config or Web.config file:在 App.config 或 Web.config 文件中:

  1. Version mismatch : The version installed via NuGet did not match the version in the config file.版本不匹配:通过 NuGet 安装的版本与配置文件中的版本不匹配。 Solution: Change the version manually in the .config file.解决方案:在 .config 文件中手动更改版本。

  2. Duplicate entries : I found duplicate entries for ValueTuple.重复条目:我发现 ValueTuple 的重复条目。 In my case one for 4.0.3.0 and another one for 4.5.0.在我的情况下,一个用于 4.0.3.0,另一个用于 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.在另一种情况下,我设法通过删除不需要的引用并完全摆脱 ValueTuple NuGet 包来解决该问题。

If you have AutoMapper version 8.0 or lower referenced in any of your projects, it's possibly the source of the issue.如果您的任何项目中引用了AutoMapper 8.0 或更低版本,则这可能是问题的根源。 See this github issue for more information.有关更多信息,请参阅此 github 问题

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.如果我理解正确,问题是 4.7 版以下的 .NET Framework 版本默认没有随附System.ValueTuple ,因此AutoMapper使用 NuGet 包引用作为程序集,因为它具有 4.7 版以下的 Framework 版本的构建目标。 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.最简单的解决方案是将您的AutoMapper引用升级到version 8.1.0或更高版本,在那里他们已经从他们的代码库中删除了程序集的所有使用并删除了依赖项。

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.我在 Windows Server 2016 上遇到了同样的错误“无法加载文件或程序集 System.ValueTuple.dll...”。但是,该站点在我的开发机器上运行良好。

My solution was simple, I grabbed this dll from my dev machine and dropped it in the site's "bin" folder on the server.我的解决方案很简单,我从我的开发机器上抓取了这个 dll 并将它放在服务器上站点的“bin”文件夹中。 It worked.有效。

I hope this isn't thread necromancy, because this is still the #1 searched thing on Google.我希望这不是线程死灵法术,因为这仍然是 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 '.问题是一个名为“ 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.我建议您检查您的软件包并查看它们的依赖项。

Right clicking References and choosing "Migrate packages.config to PackageReference..." solved the problem for me (and other similar issues).右键单击 References 并选择“将 packages.config 迁移到 PackageReference ...”解决了我的问题(以及其他类似问题)。

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.从 .NET 4.5.1 升级到 4.6.1 后,我在 AutoMapper 8.0.0.0 对版本 4.5 的依赖方面遇到了同样的问题。 Reinstalling the automapper nuget package worked for me.重新安装 automapper nuget 包对我有用。

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.如果您无法将 .Net Framework 更新到最新版本,则将 Package: Microsoft.Net.Compilers 降级到 2.10 之前的版本。 This solved the issue in my case.这解决了我的问题。

I had a library which used a newer version of the System.ValueTuple NuGet package.我有一个使用较新版本的 System.ValueTuple NuGet 包的库。 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.更新两者(或以任何方式融合它们 - 降级两者也可以) - 解决了问题。

I resolved this issue by installing System.ValueTuple from nuget.我通过从 nuget 安装 System.ValueTuple 解决了这个问题。 It was not previously installed but I guess RestSharp or another library is using it.它以前没有安装过,但我猜 RestSharp 或其他库正在使用它。

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;就我而言,我认为有些东西会从项目和框架文件夹中删除这个 dll,也许是在安装它飞过的东西时; so my project during debugging couldn't find that dll and throw that error.所以我的项目在调试期间找不到那个 dll 并抛出那个错误。 I installed我安装了

Install-Package System.ValueTuple -Version 4.5.0安装包 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.在按照上述答案进行进一步复杂的解决方案之前,安装ValueTuple 包可能适合您。

通过安装 VS 2019 解决了这个问题。

Fixed this by switching the Copy Local flag on my reference to System.ValueTuple from copy always to none.通过将我对 System.ValueTuple 的引用中的 Copy Local 标志从始终复制切换为无来修复此问题。 (It was on an assembly containing tests). (它在一个包含测试的程序集上)。

I had this issue in a Visual Studio setup/installer project.我在 Visual Studio 设置/安装程序项目中遇到了这个问题。 For some reason my project had multiple instances of System.ValueTuple.dll:出于某种原因,我的项目有多个 System.ValueTuple.dll 实例:

元组狂热

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).对于其中一个,我必须右键单击,选择“在编辑器中查找”,然后从生成的 window 中删除。否则我会遇到一个神秘的错误(如果我没记错的话,结果是“参数不正确”)。

暂无
暂无

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

相关问题 无法加载文件或程序集 System.ValueTuple Version=4.0.3.0 - Could not load file or assembly System.ValueTuple Version=4.0.3.0 加载程序集时出现异常:System.IO.FileNotFoundException:无法加载程序集“System.ValueTuple,版本 = 4.0.2.0, - Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.ValueTuple, Version=4.0.2.0, “Csc”任务意外失败无法从程序集 mscorlib Version=4.0.0.0 加载类型 System.ValueTuple 3, - The “Csc” task failed unexpectedly Could not load type System.ValueTuple 3 from assembly mscorlib Version=4.0.0.0, 如何检索 System.ValueTuple 的程序集版本? - How to retrieve the assembly version of System.ValueTuple? 如何解决无法从程序集 &#39;mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&#39; 加载类型 &#39;System.ValueTuple`3&#39;? - How to resolve Could not load type 'System.ValueTuple`3' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'? 无法在动态编译的代码中加载 System.ValueTuple - Can't load System.ValueTuple in dynamically compiled code .net核心System.ValueTuple - .net Core System.ValueTuple System.ValueTuple 4.4.0 -&gt; 4.5.0 有什么变化? - What changed in System.ValueTuple 4.4.0 -> 4.5.0? 未定义或导入预定义类型“System.ValueTuple`2” - Predefined type 'System.ValueTuple`2' is not defined or imported 在c#7中创建System.ValueTuple数组 - Creating an array of System.ValueTuple in c# 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM