无法加载文件或程序集“Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项。

60

我有一个使用VS 2013在Windows 8.1上构建的WinJS项目。

最近,我通过创建空的Javascript通用Windows 10项目并将旧项目中的所有文件添加到其中来将该项目升级为通用Windows 10。

我有Windows运行时组件和SQLite类库。

我添加了通用Windows运行时组件和通用类库,并将所有旧项目的文件复制到相应的位置。

我成功解决了所有构建错误。

我安装了所有必需的SQLite-net、Universal Windows Platform的SQLite、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.

enter image description here

Newtonsoft版本为: 9.0.1

我的Windows运行时组件的project.json文件如下:

  {
  "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并重新安装,但没有成功。


3
我之前遇到了一个新的ASP.NET Core应用程序的类似问题。结果发现其中一个被引用的库使用的Newtonsoft.Json版本比9.0.0.0低。因此,我升级了该库的版本,问题得到了解决。不确定您是否能在这里采取同样的措施解决问题。 - hbulens
嗨@hbulens,我尝试安装最新版本,但仍然会一遍又一遍地出现相同的错误。 - Kishor Bikram Oli
也许这个链接与你的问题相关 - https://github.com/aspnet/Home/issues/1609 - Sanket
25个回答

1

我曾在一个新项目中遇到类似的问题。请检查关联项目中的引用版本是否相同。


1
我通过从解决方案中删除所有NuGet包并重新安装它们来解决了这个问题。其中一个NuGet包依赖于NewtonSoft,但它没有显示在引用中。

1

我曾经遇到了与v13.0.0.0相同的问题,无论我做了什么都无法解决。我重新安装了Newtonsoft.Json,并重启了程序,还尝试了不同版本的Newtonsoft.Json。最终解决的方法是更新Visual Studio。


1

虽然这篇文章已经有一段时间了,但仍然与现在相关。希望能对某些人有所帮助。

我曾遇到同样的问题,原因是我的项目引用了一个库,而该库又间接引用了其他的库。

你可以通过在App.xaml.cs(或其他初始化程序集的地方)添加代码来解决这个问题,告诉你的应用程序如何解析它。

public App()
{
    AppDomain.CurrentDomain.AssemblyResolve += (s,a) => CurrentDomain_AssemblyResolve(s,a);
}

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    Assembly myAssembly = null;
    if (args.Name.Contains("Newtonsoft.Json,"))
    {
        myAssembly = Assembly.LoadFile(Path.Combine(ExecutingDirectory, "Newtonsoft.Json.dll"));
    }
    return myAssembly;
}

0
更新您服务器上的框架。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接