简体   繁体   English

System.TypeLoadException——无法从程序集 System.Web 加载 System.Web.Util?

[英]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.

相关问题 ASP.NET Core TypeLoadException无法从程序集“ System.Web”加载类型“ System.Web.PreApplicationStartMethodAttribute” - ASP.NET Core TypeLoadException Could not load type 'System.Web.PreApplicationStartMethodAttribute' from assembly 'System.Web' 无法从程序集&#39;System.Web,...&#39;加载类型&#39;...&#39; - Could not load type '…' from assembly 'System.Web, …' 无法从程序集 System.Web 加载类型“System.Web.HttpPostedFileBase” - Could not load type 'System.Web.HttpPostedFileBase' from assembly System.Web NUnit 测试错误:无法从程序集 'System.Web,版本 = 4.0.0.0 加载类型 'System.Web.HttpApplication' - NUnit Test Error: Could not load type 'System.Web.HttpApplication' from assembly 'System.Web, Version=4.0.0.0 System.Web 不可用 - System.Web not available 用户代码未处理System.Configuration.ConfigurationErrorsException,消息=无法加载文件或程序集&#39;System.Web - System.Configuration.ConfigurationErrorsException was unhandled by user code , Message=Could not load file or assembly 'System.Web System.IO.FileNotFoundException:无法在Mono for Android中加载程序集System.Web - System.IO.FileNotFoundException: Could not load assembly System.Web in Mono for Android 在C#中的System.Web中找不到HttpServerUtility类 - Can't find HttpServerUtility class in System.Web in C# 为什么system.web不可用? - why is system.web not available? 无法从程序集“System.Web,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50 - Could not load type 'System.Web.UI.ParseChildrenAttribute' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM