应用程序无法加载 dll
Application canot load dll
我编写了简单的控制台应用程序。
static void Main(string[] args)
{
new HttpClient().PostAsJsonAsync("URL", "Text");
}
并添加了对项目的 System.Net.Http
和 System.Net.Http.Formatting
引用。
我得到这个异常:
An unhandled exception of type 'System.IO.FileLoadException' occurred
in System.Net.Http.Formatting.dll
Additional information: Could not load file or assembly
'Newtonsoft.Json, Version=4.5.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)
检查对 "System.Net.Http"、"System.Net.Http.Formatting" 和 Newtonsoft.Json 的引用是否将复制本地设置为 True。在我的 Visual Studio 2013 中,当我添加对 System.Net.Http 的引用时,Copy Local 的默认值是 false。
您可以改为使用 nuget 为 System.Net.Http 和 Json.Net 添加程序包。我没有找到 System.Net.Http.Formatting.
的 nuget 包
"Newtonsoft.Json" 是 JSON.NET Nuget 包中的一个程序集。按照 answer to this question 中的步骤操作。
成功安装包后,您可以添加对 Newtonsoft.Json 的引用,就像对 "System.Net.Http" 所做的那样。
我编写了简单的控制台应用程序。
static void Main(string[] args)
{
new HttpClient().PostAsJsonAsync("URL", "Text");
}
并添加了对项目的 System.Net.Http
和 System.Net.Http.Formatting
引用。
我得到这个异常:
An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Net.Http.Formatting.dll
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.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)
检查对 "System.Net.Http"、"System.Net.Http.Formatting" 和 Newtonsoft.Json 的引用是否将复制本地设置为 True。在我的 Visual Studio 2013 中,当我添加对 System.Net.Http 的引用时,Copy Local 的默认值是 false。
您可以改为使用 nuget 为 System.Net.Http 和 Json.Net 添加程序包。我没有找到 System.Net.Http.Formatting.
的 nuget 包"Newtonsoft.Json" 是 JSON.NET Nuget 包中的一个程序集。按照 answer to this question 中的步骤操作。
成功安装包后,您可以添加对 Newtonsoft.Json 的引用,就像对 "System.Net.Http" 所做的那样。