无法加载文件或程序集 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一
Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies
我有一个以前使用 VS 2013 在 Windows 8.1 上构建的 WinJS 项目。
最近我通过创建一个空白 Javascript Universal windows 10 项目将此项目升级到 Universal Windows 10,然后添加了旧项目中的所有文件。
我有 Windows 运行时组件和 Class SQLite 库。
我添加了通用 Windows 运行时组件和通用 Class 库并将我的所有文件从旧项目复制到相应的位置。
我以某种方式设法消除了所有构建错误。
我安装了所有必需的 SQLite-net、SQLite for Universal Windows Platform、Newtonsoft 等
但是当我 运行 应用程序并在 Windows 运行时组件中调用本地方法时,它给出了一些奇怪的错误,如:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code.
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Newtonsoft 版本为:9.0.1
我的 project.json 文件 Windows 运行时组件具有以下内容:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
我的 Visual Studio 版本是:
我尝试删除所有 Newtonsoft json 并重新安装它,但没有成功。
我做了一个基础的Demo,重现了这个问题。似乎 WinRT 组件未能找到 Newton.Json
的正确程序集。暂时的解决方法是手动添加 Newtonsoft.json.dll
文件。您可以通过以下步骤实现:
右键引用->添加引用->浏览...->找到C:\Users\.nuget\packages\Newtonsoft.Json.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.json.dll->点击添加按钮.
重建您的运行时组件项目并运行。这个错误应该消失了。
不久前,我在一个新的 ASP.NET Core 应用程序中遇到了类似的问题。事实证明,其中一个引用的库使用了低于 9.0.0.0 的 Newtonsoft.Json 版本。所以我升级了那个库的版本,问题就解决了。不确定您是否可以在这里做同样的事情
我也有同样的问题,要解决这个问题,如果 Newtonsoft.Json[=23= 的版本,请检查项目的 References ] 已更新(可能没有),然后将其删除并检查您的 Web.config 或 App.config wheter元素 dependentAssembly 更新如下:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
之后,再次重建项目(dll将被替换为正确的版本)
我的 ASP.NET 核心项目遇到过类似的问题。
bin/debug-folder 中的 .config 文件是这样生成的:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
如果我手动将第二个 bindingRedirect 更改为此它有效:
<bindingRedirect oldVersion="9.0.0.0" newVersion="10.0.0.0" />
不知道为什么会这样。
我正在使用 Visual Studio 2015 和 .Net Core SDK 1.0.0-preview2-1-003177。
我正在使用 Visual Studio 2013 更新 2。就我而言,我在一个解决方案中有一个 Web 项目和一个 Web Api 项目以及单元测试项目和其他 class 库。
我花了几天时间解决了这个问题。以下是我找到的分步解决方案。
- 右键单击 Web Api 项目。 Select "设置为启动项目"
- 右键单击 Web Api 项目。转到 属性(Alt + Enter)。
- 在左侧菜单的“应用程序”选项卡上,select 应用程序
- 找到目标框架。将其更改为 4.5.1 并保存。但是,它在 "Error List" window 中显示错误。 Rebuild后没有报错。
- 通过使用 Package Manager Console 中的以下查询从解决方案中删除 所有
Newtonsoft.Json
包(以获取它 查看 > 其他 Window > 程序包管理器控制台).
uninstall-package newtonsoft.json -force
- 从 包管理器控制台重新安装
Newtonsoft.Json
install-package newtonsoft.json
- 如果您有 Visual Studio 2013 的最新更新,您可能不会遇到此问题。由于我使用的是 Update 2,因此,在尝试安装
Newtonsoft.Json
时,我遇到了以下错误。
The 'Newtonsoft.Json 10.0.3' package requires NuGet client version
'2.12' or above, but the current NuGet version i s '2.8.50313.46'
- 要解决这个问题,我们需要更新包管理器控制台。到了
工具 > 扩展和更新...> 在左窗格中.. select 更新 > Visual Studio 图库.
更新 NuGet 包管理器扩展。按照之后的步骤进行操作。
Visual Studio 之后需要重启。
再次执行步骤 6。
安装后 packages.config 将添加下面这行
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net451" />
安装后 web.config 将添加以下行
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
如果没有其他错误就执行成功了
我通过在启动项目的NuGet中添加Newtonsoft.Json解决了这个问题(尽管它并没有直接在启动项目中使用)。
就我而言,这是配置文件的问题 web.config
在我的机器上,当我更新 newton 版本时,VS 自动修复了我的 web.config 文件以指向新版本。当我将其上传到生产环境时,现有 web.config 指向旧版本。
我更新 web.config 后它又开始工作了。
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
我们花了一天的时间来解决这个问题。解决方案是强制您的网络服务在 web.config 文件中使用版本 11.0.0。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
通过使用包管理器更新我的 Newton.Json 版本(旧版本 = 9.0.0.0 到新版本 11.0.0.0),能够解决我的 asp.net mvc 项目中的这个问题。
我认为 AutoCAD 劫持了我的。对我有用的解决方案是将其劫持回来。我从 https://forums.autodesk.com/t5/navisworks-api/could-not-load-file-or-assembly-newtonsoft-json/td-p/7028055?profile.language=en 得到这个 - 是的,互联网以神秘的方式运作。
// in your initilizer ...
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
.....
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Newtonsoft.Json"))
{
string assemblyFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\Newtonsoft.Json.dll";
return Assembly.LoadFrom(assemblyFileName);
}
else
return null;
}
更新'Newtonsoft'版本可以解决问题
在Visual Studio 2015中可以右击"Solution"和select"Manage Nuget packages for solution",搜索"Newtonsoft"select一个更多当前版本并单击更新。
在配置文件 (web.config) 中为 Newtonsoft.Json 添加绑定重定向配置将解决问题。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
因为 Newtonsoft.Json 您的版本是 9,请在配置中适当更新版本。
如果此配置不起作用,请确保配置标记中的名称space (xmlns) 正确或完全删除名称space。
Assembly binding redirect does not work
一个需要更新Newtonsoft.Json-Version
转到工具 => NuGet 包管理器 => 包管理器控制台
并在程序包管理器控制台 Window.
中键入 Install-Package Newtonsoft.Json -Version 12.0.2
我有一个非常相似的问题。我试图在 .NET DLL 中使用 Newtonsoft.Json.dll,就像我在计算机上的 .NET EXE 中成功使用它一样。我在 Visual Studio 2017 年使用 NuGet 将 Newtonsoft.Json 添加到 MyDll.dll。 MyExecutable.exe 引用 MyDll.dll。从 MyDll.dll 中的代码调用 Newtonsoft.Json 方法引发 "System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".
我运行微软的fuslogvw.exehttps://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer检查正在加载的内容,发现如下:
LOG: Post-policy reference: Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/MyExecutable/bin/Debug/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\MyExecutable\bin\Debug\Newtonsoft.Json.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
MyExecutable.exe 没有对 Newtonsoft.Json 的引用或调用,但我在 bin\Debug 目录中找到了 6.0.0.0 Newtonsoft.Json.dll 我之前的 MyExecutable 源代码树副本我添加了对我的任何代码的任何 Newtonsoft.Json 引用。我不知道为什么 6.0.0.0 Newtonsoft.Json.dll 在那里。也许它被 MyExecutable 引用的另一个 DLL 引用了。我通过使用 NuGet 将对 12.0.0.0 Newtonsoft.Json 的引用添加到 MyExecutable.
来避免 FileLoadException
我希望如下所示的 MyExecutable App.config 中的绑定重定向可以替代 MyExecutable 的引用 Newtonsoft.Json,但它没有用。
……
我在使用以下版本 12.0.3 时遇到了同样的问题:
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
此问题仅出现在我的测试项目 (xUnit) 中,并且是由于此项目.
缺少newtonsoft.json
引起的
重要的是,我正在测试另一个项目的代码,其中附加了库并且工作正常。
我通过从解决方案中删除所有 NuGet 包并重新安装它们解决了这个问题。
其中一个 NuGet 包依赖于 NewtonSoft,它没有在参考文献中显示
当我将 Nuget 包 Newtonsoft.Json 12.0.0.2 添加到我的两个 .netstandard 库项目中时,我遇到了这个问题,它几乎花了我一整天的时间来解决这个问题。
异常-:无法加载文件或程序集'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'。系统找不到指定的文件。
解决方案-:我不得不从 Nuget 中删除包并转到以下位置并执行后续步骤-
步骤 1. 转到位置“C:\Users[用户名].nuget\packages\newtonsoft.json.0.2\lib”
在这里您将获得您之前安装的所有 Nuget 版本。
第 2 步。因为我想在我的 .netstandard 2.0 库项目中使用它,所以我从这个位置复制了“netstandard2.0”文件夹并粘贴到我喜欢的位置(**我通常保留第 3 方 dll 的地方).
第 3 步。现在我将此处的 DLL 引用添加到我的两个项目中,这样问题就解决了。
谢谢
从该解决方案的所有项目中删除所有 BIN 和 OBj 文件夹。此外,在使用时更新所有项目的包。删除包文件夹并重建 运行。它对我有用。
我在新项目中遇到了类似的问题。检查附属项目中的参考版本是否相同。
我有一个以前使用 VS 2013 在 Windows 8.1 上构建的 WinJS 项目。
最近我通过创建一个空白 Javascript Universal windows 10 项目将此项目升级到 Universal Windows 10,然后添加了旧项目中的所有文件。
我有 Windows 运行时组件和 Class SQLite 库。
我添加了通用 Windows 运行时组件和通用 Class 库并将我的所有文件从旧项目复制到相应的位置。
我以某种方式设法消除了所有构建错误。
我安装了所有必需的 SQLite-net、SQLite for Universal Windows Platform、Newtonsoft 等
但是当我 运行 应用程序并在 Windows 运行时组件中调用本地方法时,它给出了一些奇怪的错误,如:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code.
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Newtonsoft 版本为:9.0.1
我的 project.json 文件 Windows 运行时组件具有以下内容:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
我的 Visual Studio 版本是:
我尝试删除所有 Newtonsoft json 并重新安装它,但没有成功。
我做了一个基础的Demo,重现了这个问题。似乎 WinRT 组件未能找到 Newton.Json
的正确程序集。暂时的解决方法是手动添加 Newtonsoft.json.dll
文件。您可以通过以下步骤实现:
右键引用->添加引用->浏览...->找到C:\Users\.nuget\packages\Newtonsoft.Json.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.json.dll->点击添加按钮.
重建您的运行时组件项目并运行。这个错误应该消失了。
不久前,我在一个新的 ASP.NET Core 应用程序中遇到了类似的问题。事实证明,其中一个引用的库使用了低于 9.0.0.0 的 Newtonsoft.Json 版本。所以我升级了那个库的版本,问题就解决了。不确定您是否可以在这里做同样的事情
我也有同样的问题,要解决这个问题,如果 Newtonsoft.Json[=23= 的版本,请检查项目的 References ] 已更新(可能没有),然后将其删除并检查您的 Web.config 或 App.config wheter元素 dependentAssembly 更新如下:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
之后,再次重建项目(dll将被替换为正确的版本)
我的 ASP.NET 核心项目遇到过类似的问题。 bin/debug-folder 中的 .config 文件是这样生成的:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
如果我手动将第二个 bindingRedirect 更改为此它有效:
<bindingRedirect oldVersion="9.0.0.0" newVersion="10.0.0.0" />
不知道为什么会这样。
我正在使用 Visual Studio 2015 和 .Net Core SDK 1.0.0-preview2-1-003177。
我正在使用 Visual Studio 2013 更新 2。就我而言,我在一个解决方案中有一个 Web 项目和一个 Web Api 项目以及单元测试项目和其他 class 库。
我花了几天时间解决了这个问题。以下是我找到的分步解决方案。
- 右键单击 Web Api 项目。 Select "设置为启动项目"
- 右键单击 Web Api 项目。转到 属性(Alt + Enter)。
- 在左侧菜单的“应用程序”选项卡上,select 应用程序
- 找到目标框架。将其更改为 4.5.1 并保存。但是,它在 "Error List" window 中显示错误。 Rebuild后没有报错。
- 通过使用 Package Manager Console 中的以下查询从解决方案中删除 所有
Newtonsoft.Json
包(以获取它 查看 > 其他 Window > 程序包管理器控制台).
uninstall-package newtonsoft.json -force
- 从 包管理器控制台重新安装
Newtonsoft.Json
install-package newtonsoft.json
- 如果您有 Visual Studio 2013 的最新更新,您可能不会遇到此问题。由于我使用的是 Update 2,因此,在尝试安装
Newtonsoft.Json
时,我遇到了以下错误。
The 'Newtonsoft.Json 10.0.3' package requires NuGet client version '2.12' or above, but the current NuGet version i s '2.8.50313.46'
- 要解决这个问题,我们需要更新包管理器控制台。到了
工具 > 扩展和更新...> 在左窗格中.. select 更新 > Visual Studio 图库.
更新 NuGet 包管理器扩展。按照之后的步骤进行操作。
Visual Studio 之后需要重启。
再次执行步骤 6。
安装后 packages.config 将添加下面这行
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net451" />
安装后 web.config 将添加以下行
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
如果没有其他错误就执行成功了
我通过在启动项目的NuGet中添加Newtonsoft.Json解决了这个问题(尽管它并没有直接在启动项目中使用)。
就我而言,这是配置文件的问题 web.config 在我的机器上,当我更新 newton 版本时,VS 自动修复了我的 web.config 文件以指向新版本。当我将其上传到生产环境时,现有 web.config 指向旧版本。
我更新 web.config 后它又开始工作了。
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
我们花了一天的时间来解决这个问题。解决方案是强制您的网络服务在 web.config 文件中使用版本 11.0.0。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
通过使用包管理器更新我的 Newton.Json 版本(旧版本 = 9.0.0.0 到新版本 11.0.0.0),能够解决我的 asp.net mvc 项目中的这个问题。
我认为 AutoCAD 劫持了我的。对我有用的解决方案是将其劫持回来。我从 https://forums.autodesk.com/t5/navisworks-api/could-not-load-file-or-assembly-newtonsoft-json/td-p/7028055?profile.language=en 得到这个 - 是的,互联网以神秘的方式运作。
// in your initilizer ...
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
.....
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Newtonsoft.Json"))
{
string assemblyFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\Newtonsoft.Json.dll";
return Assembly.LoadFrom(assemblyFileName);
}
else
return null;
}
更新'Newtonsoft'版本可以解决问题
在Visual Studio 2015中可以右击"Solution"和select"Manage Nuget packages for solution",搜索"Newtonsoft"select一个更多当前版本并单击更新。
在配置文件 (web.config) 中为 Newtonsoft.Json 添加绑定重定向配置将解决问题。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
因为 Newtonsoft.Json 您的版本是 9,请在配置中适当更新版本。
如果此配置不起作用,请确保配置标记中的名称space (xmlns) 正确或完全删除名称space。
Assembly binding redirect does not work
一个需要更新Newtonsoft.Json-Version 转到工具 => NuGet 包管理器 => 包管理器控制台 并在程序包管理器控制台 Window.
中键入 Install-Package Newtonsoft.Json -Version 12.0.2我有一个非常相似的问题。我试图在 .NET DLL 中使用 Newtonsoft.Json.dll,就像我在计算机上的 .NET EXE 中成功使用它一样。我在 Visual Studio 2017 年使用 NuGet 将 Newtonsoft.Json 添加到 MyDll.dll。 MyExecutable.exe 引用 MyDll.dll。从 MyDll.dll 中的代码调用 Newtonsoft.Json 方法引发 "System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".
我运行微软的fuslogvw.exehttps://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer检查正在加载的内容,发现如下:
LOG: Post-policy reference: Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/MyExecutable/bin/Debug/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\MyExecutable\bin\Debug\Newtonsoft.Json.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
MyExecutable.exe 没有对 Newtonsoft.Json 的引用或调用,但我在 bin\Debug 目录中找到了 6.0.0.0 Newtonsoft.Json.dll 我之前的 MyExecutable 源代码树副本我添加了对我的任何代码的任何 Newtonsoft.Json 引用。我不知道为什么 6.0.0.0 Newtonsoft.Json.dll 在那里。也许它被 MyExecutable 引用的另一个 DLL 引用了。我通过使用 NuGet 将对 12.0.0.0 Newtonsoft.Json 的引用添加到 MyExecutable.
来避免 FileLoadException我希望如下所示的 MyExecutable App.config 中的绑定重定向可以替代 MyExecutable 的引用 Newtonsoft.Json,但它没有用。 ……
我在使用以下版本 12.0.3 时遇到了同样的问题:
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
此问题仅出现在我的测试项目 (xUnit) 中,并且是由于此项目.
缺少newtonsoft.json
引起的
重要的是,我正在测试另一个项目的代码,其中附加了库并且工作正常。
我通过从解决方案中删除所有 NuGet 包并重新安装它们解决了这个问题。 其中一个 NuGet 包依赖于 NewtonSoft,它没有在参考文献中显示
当我将 Nuget 包 Newtonsoft.Json 12.0.0.2 添加到我的两个 .netstandard 库项目中时,我遇到了这个问题,它几乎花了我一整天的时间来解决这个问题。
异常-:无法加载文件或程序集'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'。系统找不到指定的文件。
解决方案-:我不得不从 Nuget 中删除包并转到以下位置并执行后续步骤-
步骤 1. 转到位置“C:\Users[用户名].nuget\packages\newtonsoft.json.0.2\lib” 在这里您将获得您之前安装的所有 Nuget 版本。
第 2 步。因为我想在我的 .netstandard 2.0 库项目中使用它,所以我从这个位置复制了“netstandard2.0”文件夹并粘贴到我喜欢的位置(**我通常保留第 3 方 dll 的地方).
第 3 步。现在我将此处的 DLL 引用添加到我的两个项目中,这样问题就解决了。
谢谢
从该解决方案的所有项目中删除所有 BIN 和 OBj 文件夹。此外,在使用时更新所有项目的包。删除包文件夹并重建 运行。它对我有用。
我在新项目中遇到了类似的问题。检查附属项目中的参考版本是否相同。