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

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

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

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


当前回答

我让微软Office的Siemens Teamcenter 10客户端用户得到关于不同DLL的相同错误。其他答案都没用。解决方案是删除文件夹

C:\Users\%username%\AppData\Local\assembly\

其他回答

在我的情况下,我想编译一个COM可见DLL。问题是这个DLL的旧版本位于这里:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

因此Visual Studio加载这个版本,而不是新编译的版本,因为它试图注册它。

这可以在引用COM包装器dll时发生。在Visual Studio项目中,在References下,选择要引用的COM包装器dll,并确保它们具有以下属性值:"Embed Interop Types": False和"Specific Version": False。

要知道清除什么确定-添加以下注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog (DWord set to 1).

然后您将看到如下所示的输出。这将告诉你asp.net试图加载dll的位置。清除该目录。

LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\app\AtlasAdvisor\web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL **file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3c8629f7/dfa387b6/Avanade.ViddlerNet.DLL.**
LOG: Attempting download of new URL **file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/3c8629f7/dfa387b6/Avanade.ViddlerNet/Avanade.ViddlerNet.DLL**.

删除这些文件夹中的所有文件。

C: / Windows / Microsoft.NET/Framework/v4.0.30319/Temporary ASP。网络文件 C: / Windows / Microsoft.NET/Framework64/v4.0.30319/Temporary ASP。网 文件

我只是从这个路径中删除了我的应用程序临时数据

C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files

问题解决