【问题标题】:Application canot load dll应用程序无法加载 dll
【发布时间】:2015-04-01 22:44:46
【问题描述】:

我编写了简单的控制台应用程序。

static void Main(string[] args)
{
    new HttpClient().PostAsJsonAsync("URL", "Text");
}

并将System.Net.HttpSystem.Net.Http.Formatting 引用添加到项目中。

我得到了这个例外:

发生“System.IO.FileLoadException”类型的未处理异常 在 System.Net.Http.Formatting.dll 中

附加信息:无法加载文件或程序集 'Newtonsoft.Json,版本=4.5.0.0,文化=中性, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一。这 定位程序集的清单定义与程序集不匹配 参考。 (HRESULT 异常:0x80131040)

【问题讨论】:

  • 什么IDE?您是否检查了图书馆的位置和预期位置?
  • 你有 Newtonsoft.Json 依赖吗?
  • 在接受的答案中检查此link 和 msdn.blog 链接。
  • 我使用的是 Visual Studio 2013。MSDN 上没有提到 Newtonsoft.Json,在方法的描述中,现在我通过 nuget 安装了 JSON.net 包,但得到了相同的异常。

标签: c# .net


【解决方案1】:

“Newtonsoft.Json”是来自 JSON.NET Nuget 包的程序集。按照answer to this question 中的步骤操作。

成功安装软件包后,您可以添加对 Newtonsoft.Json 的引用,就像您为“System.Net.Http”所做的那样。

【讨论】:

  • 在我安装包时自动添加了对 Newtonsoft.Json 的引用。还是一样的例外。
【解决方案2】:

检查对“System.Net.Http”、“System.Net.Http.Formatting”和 Newtonsoft.Json 的引用是否将 Copy Local 设置为 True。在我的 Visual Studio 2013 上,当我添加对 System.Net.Http 的引用时,Copy Local 的默认值为 false。

您可以改为使用 nuget 为 System.Net.Http 和 Json.Net 添加包。我没有找到 System.Net.Http.Formatting 的 nuget 包。

【讨论】:

  • 我在nuget中找到了Microsoft.Net.Http,并安装了它,之后它就可以工作了。有点不清楚,但问题解决了。
  • System.Net.Http 可能是使用不同版本的 Newtonsoft.Json 构建的,该版本具有不同的 stong name。当您为Newtonsoft.Json Nuget adds assembly binding redirects 添加包时。对程序集绑定重定向的更好描述是 here。您可以使用它来将强命名程序集引用指向这些程序集的较新版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-15
  • 1970-01-01
  • 2018-09-06
  • 2017-02-03
相关资源
最近更新 更多