[英]System.TypeLoadException--can't load System.Web.Util from assembly System.Web?
I am attempting to create a program that loads IMDB data from the OMDb API upon getting a request containing the name of the movie to get data from.我正在尝试创建一个程序,在收到包含要从中获取数据的电影名称的请求后,从 OMDb API 加载 IMDB 数据。 When I run the program, testing it by trying to get data from the movie The Shawshank Redemption , I get this error:
当我运行程序,通过尝试从电影The Shawshank Redemption中获取数据来测试它时,我得到了这个错误:
Could not load type 'System.Web.Util.Utf16StringValidator' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.无法从程序集“System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.Util.Utf16StringValidator”。
using (WebClient wc = new WebClient())
{
var json = wc.DownloadString(url);
JavaScriptSerializer oJS = new JavaScriptSerializer();
ImdbEntity obj = new ImdbEntity();
obj = oJS.Deserialize<ImdbEntity>(json); // This is the line that causes the problem in debug.
if (obj.Response == "True")
{
string txtActor = obj.Actors;
string txtDirector = obj.Director;
string txtYear = obj.Year;
}
else
{
Console.WriteLine("Movie not found.");
}
}
(Yes, I am getting the code from another StackOverflow question, but I'm an absolute beginner at this.) (是的,我正在从另一个 StackOverflow 问题中获取代码,但我是这方面的绝对初学者。)
I have System.Web.Extensions.dll referenced in my project (and have the using statement using System.Web.Script.Serialization ).我在我的项目中引用了 System.Web.Extensions.dll(并且使用 System.Web.Script.Serialization的 using 语句)。
remove all references to other json converters.删除对其他 json 转换器的所有引用。
add Newtonsoft.Json NuGet package (version 12.0.3 worked for me)添加 Newtonsoft.Json NuGet package(版本 12.0.3 对我有用)
obj = JsonConvert.DeserializeObject<ImdbEntity>(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.