System.TypeLoadException--can't load System.Web.Util from assembly System.Web?

852 views Asked by At

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. When I run the program, testing it by trying to get data from the movie The Shawshank Redemption, I get this error:

Could not load type 'System.Web.Util.Utf16StringValidator' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

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.)

I have System.Web.Extensions.dll referenced in my project (and have the using statement using System.Web.Script.Serialization).

1

There are 1 answers

0
Super Richman On

remove all references to other json converters.

add Newtonsoft.Json NuGet package (version 12.0.3 worked for me)

obj = JsonConvert.DeserializeObject<ImdbEntity>(json);