最近我在c#解决方案中遇到了以下异常:

错误2无法加载文件或程序集'Newtonsoft。Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6'或 它的依赖项之一。参数不正确。(例外 HRESULT: 0x80070057 (E_INVALIDARG))

这既不取决于我的代码,也不取决于程序集的名称(如Newtonsoft)。Json)。

当我从解决方案中删除这个dll时,编译器会在相同的异常中告诉另一个dll。所以我想我的电脑应该关闭/打开一些东西:)


当前回答

该问题与引用类库的. net运行时版本有关(展开引用,选择库并勾选“运行时版本”)。我在Antlr3上遇到了点问题。运行时,在将我的visual studio项目升级到v4.5之后。我用NuGet卸载了Microsoft ASP。NET Web优化框架(由于依赖链阻止我直接卸载Antlr3)

然后我用NuGet重新安装了Microsoft ASP。NET Web优化框架。这将重新安装正确的运行时版本。

其他回答

我在IIS上运行的“Chocolatey服务器(简单)”也有同样的问题,必须执行以下步骤

Clean the "C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files" as recommended Uninstall the "Chocolatey Server (Simple)" application via choco Remove the directory "C:\tools\chocolatey.server" from the chocolatey package directory. Important, because otherwise Web.config is holding old dependencies which leads to the error. A simple re-installation will not update an existing Web.config (as it was in my case). Restart IIS and config Chocolatey Server as recommended by the authors. The chocolatey server page should now be visible without any errors.

从源代码控制处获得一组新的二进制文件会有所帮助。

谢谢

清除临时框架文件为您的项目:-

C:\WINDOWS\ Microsoft.NET \ Framework \ v2.0.50727 \临时ASP。网络文件\

谢谢你,亚历克斯,你的第二点帮我解决了这个问题。

除非你在Windows 7中以管理员身份运行visual studio,否则它将临时文件存储在本地,而不是C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP. net。网络文件。

参见以下博客文章:http://www.dotnetscraps.com/dotnetscraps/post/Location-of-Temporary-ASPNET-files-in-Vista-or-Windows-7.aspx

如果还有其他人在使用WiX工具集,我发现我的安装程序项目引用了一个最近从解决方案中删除的旧项目。我花了一段时间才意识到,因为在我试图构建的解决方案中有许多项目,并且消息没有指出哪个项目构建失败了(以及干净的,哪个项目也失败了)。