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

Kis*_*Oli 27 c# visual-studio win-universal-app windows-10 windows-10-universal

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

最近我通过创建一个空白的Javascript Universal windows 10项目将该项目升级到Universal Windows 10,然后从旧项目添加了我的所有文件.

我有Windows运行时组件以及SQLite的类库.

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

不知何故,我设法删除所有构建错误.

我安装了所有必需的SQLite-net,SQLite for Universal Windows Platform,Newtonsoft等.

但是当我运行应用程序并在Windows运行时组件中调用Native方法时,它会产生一些奇怪的错误:

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

我的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": {}
  }
}
Run Code Online (Sandbox Code Playgroud)

我的Visual Studio版本是:

在此输入图像描述

我尝试删除所有的Newtonsoft json并重新安装它,但没有运气.

Elv*_*SFT 28

我做了一个基本的演示并重现了这个问题.似乎WinRT组件未能找到正确的程序集Newton.Json.暂时解决方法是手动添加Newtonsoft.json.dll文件.您可以通过以下步骤实现此目的:

  1. 右键单击引用 - >添加引用 - >浏览...->查找C:\ Users\.nuget\packages\Newtonsoft.Json\9.0.1\lib\portable-net45 + wp80 + win8 + wpa81\Newtonsoft.json. dll->单击"添加"按钮.

  2. 重建Runtime Component项目并运行.这个错误应该消失了.


Jfl*_*fly 21

我通过将Newtonsoft.Json添加到启动项目的NuGet来解决了这个问题.

  • 天啊!我一天中的几个小时和几个小时都浪费了。希望我很久以前就看过这个答案。谢谢!奇怪的是,我从未在启动项目中使用过 Newtonsoft.Json,而且它已经工作了几个月。然后今天,它决定投诉。 (5认同)
  • 传奇!甚至在启动项目(它是一个控制台应用程序)中都没有引用或需要,但在添加后修复了我的类库中的问题 (3认同)
  • 为我们的 ASP.NET Core 1.0.1 Web 应用程序工作。将 Json.NET 添加到 Startup 类所在的项目中并且它可以工作。谢谢。 (2认同)

Ric*_*Lee 15

我有同样的问题也一样,要解决这个问题,您在引用您的项目,如果版本Newtonsoft.Json被更新(probablly鸵鸟政策),然后将其删除,并在您检查任何Web.config文件App.config中 wheter的element 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>
Run Code Online (Sandbox Code Playgroud)

之后,再次重建项目(dll将替换为正确的版本)


Kun*_*osh 8

我正在使用Visual Studio 2013 Update 2.就我而言,我在一个解决方案中有一个Web项目和一个Web Api项目和单元测试项目以及其他类库.

我花了几天时间来解决这个问题.以下是我找到的逐步解决方案.

  1. 右键单击Web Api项目.选择" 设为启动项目 "
  2. 右键单击Web Api项目.转到属性(Alt + Enter).
  3. 在左侧菜单的"应用程序"选项卡上,选择" 应用程序"
  4. 查找目标框架.将其更改为4.5.1并保存.但是,它在"错误列表"窗口中显示错误.重建后,没有错误.
  5. Newtonsoft.JsonPackage Manager控制台使用以下查询从解决方案中删除所有包(以获取它查看>其他窗口>包管理器控制台).

uninstall-package newtonsoft.json -force

  1. Newtonsoft.JsonPackage Manager控制台重新安装

install-package newtonsoft.json

  1. 如果您有Visual Studio 2013的最新更新,则可能不会遇到此问题.因为我正在使用Update 2,所以,在尝试安装时Newtonsoft.Json,我遇到了以下错误.

'Newtonsoft.Json 10.0.3'软件包需要NuGet客户端版本'2.12'或更高版本,但当前的NuGet版本是'2.8.50313.46'

  1. 要解决此问题,我们需要更新程序包管理器控制台.得到了

工具>扩展和更新...>在左窗格中..选择更新> Visual Studio库.

  1. 更新NuGet包管理器扩展.按照之后的步骤进行操作.

  2. Visual Studio将在此之后重新启动.

  3. 再次执行步骤6.

安装完成后,将在下面的行中添加packages.config

  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net451" />
Run Code Online (Sandbox Code Playgroud)

安装完成后,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>
Run Code Online (Sandbox Code Playgroud)

如果没有其他错误,它将成功执行.


hbu*_*ens 6

前一段时间我在使用新的ASP.NET Core应用程序时遇到了类似的问题.事实证明,其中一个引用的库使用的Newtonsoft.Json版本低于9.0.0.0.所以我升级了该库的版本,问题解决了.不确定你是否能够在这里做同样的事情


Var*_*run 6

在配置文件 (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>
Run Code Online (Sandbox Code Playgroud)

由于您的案例中的 Newtonsoft.Json 版本是 9,请在配置中适当更新版本。

如果此配置不起作用,请确保配置标记中的命名空间 (xmlns) 正确或完全删除命名空间。

程序集绑定重定向不起作用


CAD*_*oke 5

我认为 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;
}
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

101907 次

最近记录:

6 年,10 月 前