无法加载文件或程序集“系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089"或其依赖项之一 [英] Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies

查看:31
本文介绍了无法加载文件或程序集“系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089"或其依赖项之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一些用户机器上产生了这个异常(大约 20 个):

I have this exception generated on some user machines (~1 of 20):

无法加载文件或程序集 'System, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089' 或其之一依赖关系.系统找不到指定的文件.

Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

我在网络和这个网站上发现了几个关于这个错误的引用,但没有任何帮助.

I found several references to this error over the web and this site but nothing helped.

我有一个使用 WCF 连接到服务器的加载项应用程序.使用 .NET Framework 3.5 和 VS 2008 构建的加载项.

I have an add-in application which uses WCF to connect to the server. The add-in built with .NET Framework 3.5 with VS 2008.

只有一个用户帐户可以在其中一台测试机器上重现该错误.我安装了我的应用程序,并且只能从这台机器上的一个帐户复制它,其他任何地方都可以正常工作.此外,它只能通过我为其创建插件的一个版本的主机应用程序来重现(我假设是因为它使用了不同的 .NET 框架).

The error is reproducible on one of the test machines in only one user account. I install my application and can only reproduce this from one account on this machine everywhere else it is working fine. Furthermore it is only reproducible with only one version of host application which I created add-in for (I assume because it uses differnet .NET Frameworks).

我检查了保险丝日志并看到以下内容:

I have checked the fuse logs and I see the following:

Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v2.0.50727mscorwks.dll
Running under executable  C:Program FilesSolidWorks CorpSolidWorkssldworks.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = HomeUser
LOG: DisplayName = System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files/SolidWorks Corp/SolidWorks/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.


所以由于某些原因,它试图使用 v2.0.50727mscorwks.dll 加载器来加载 System.dll<的 Version=4.0.0.0/代码>.在构建机器上,我指的是 System.dll 的 2.0.0.0 版本.


So by some reasons it is trying to use v2.0.50727mscorwks.dll loader to load the Version=4.0.0.0 of System.dll. On build machine I'm referring 2.0.0.0 version of System.dll.

推荐答案

我也遇到了同样的问题 - 一些用户可以从 git 中提取并且一切运行正常.有些人会拉取并得到一个非常相似的异常:

I had this same problem - some users could pull from git and everything ran fine. Some would pull and get a very similar exception:

无法加载文件或程序集...、Version=...、Culture=neutral、PublicKeyToken=..."或其依赖项之一.系统找不到指定的文件.

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

在我的特殊情况下是 AjaxMin,所以实际的错误看起来像这样,但细节并不重要:

In my particular case it was AjaxMin, so the actual error looked like this but the details don't matter:

无法加载文件或程序集AjaxMin,版本=4.95.4924.12383,Culture=neutral,PublicKeyToken=21ef50ce11b5d80f"或其依赖项之一.系统找不到指定的文件.

Could not load file or assembly 'AjaxMin, Version=4.95.4924.12383, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.

原来是对解决方案执行以下操作的结果:

It turned out to be a result of the following actions on a Solution:

  1. 已为解决方案启用 NuGet 包还原.

  1. NuGet Package Restore was turned on for the Solution.

添加了一个项目,并在其中安装了一个 Nuget 包(本例中为 AjaxMin).

A Project was added, and a Nuget package was installed into it (AjaxMin in this case).

项目已移至解决方案中的不同文件夹.

The Project was moved to different folder in the Solution.

Nuget 包已更新至较新版本.

The Nuget package was updated to a newer version.

这个错误开始缓慢但肯定地开始出现在一些用户面前.

And slowly but surely this bug started showing up for some users.

原因是解决方案级别的 packages/respositories.config 保留了旧的项目引用,现在有一个新的第二个条目用于移动的项目.换句话说,它在重组之前就有这个:

The reason was the Solution-level packages/respositories.config kept the old Project reference, and now had a new, second entry for the moved Project. In other words it had this before the reorg:

  <repository path="..Oldpackages.config" />

重组后的这个:

  <repository path="..Oldpackages.config" />
  <repository path="..Newpackages.config" />

所以第一行现在指的是一个项目,当它在磁盘上时,不再是我的解决方案的一部分.

So the first line now refers to a Project that, while on disk, is no longer part of my Solution.

启用 Nuget 包还原后,将读取两个 packages.config 文件,每个文件都指向各自的 Nuget 包和包版本列表.然而,在将 Nuget 包更新到较新版本之前,没有任何冲突.

With Nuget Package Restore on, both packages.config files were being read, which each pointed to their own list of Nuget packages and package versions. Until a Nuget package was updated to a newer version however, there weren't any conflicts.

但是,一旦 Nuget 包更新,只有活动项目的存储库列表才会更新.NuGet Package Restore 选择仅下载一个版本的库 - 它在 repositories.config 中遇到的第一个版本,它是较旧的版本.编译器和 IDE 继续进行,就好像它选择了较新的一样.结果是运行时异常,提示缺少 DLL.

Once a Nuget package was updated, however, only active Projects had their repositories listings updated. NuGet Package Restore chose to download just one version of the library - the first one it encountered in repositories.config, which was the older one. The compiler and IDE proceeded as though it chose the newer one. The result was a run-time exception saying the DLL was missing.

答案显然是从该文件中删除所有引用了不在您的解决方案中的项目的行.

The answer obviously is to delete any lines from this file that referenced Projects that aren't in your Solution.

这篇关于无法加载文件或程序集“系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089"或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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