Windows Form Error: Could not load file or assembly Newtonsoft.Json or one of its dependencies. The system cannot find the file specified

Last Reply 6 months ago By Waghmare

Posted 6 months ago

Hi team,

Please help me to call my WEB api from win form application.

I am getting error as below. Please suggest me change in my code or new solution i have tried below link solution but not works. - 

Call (Consume) Web API in Windows Forms Application using C#

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

at Line : 

 HttpResponseMessage response_1 = client.PostAsJsonAsync("/api/AddEmployee/Post", addEmployees_1).Result;

 C# win form code

            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            List<AddEmployee> AddEmployee_List = (List<AddEmployee>)javaScriptSerializer.Deserialize(jsonstring, typeof(List<AddEmployee>));

            foreach (AddEmployee addEmployees_1 in AddEmployee_List)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:63481/");

                    HttpResponseMessage response_1 = client.PostAsJsonAsync("/api/AddEmployee/Post", addEmployees_1).Result;
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    if (response_1.IsSuccessStatusCode)
                    {
                        label1.Text = "Success";
                    }
                }
            }

 

Posted 6 months ago

Hi Waghmare,

The error means .Net couldn't find the Json.NET library.

Do you have install it?

If not use NuGet package manager and install it.


Posted 6 months ago

Thanks a ton @Dharmendr sir.. Issue is with DLL file which was not added in client app [Win app].After adding it works fine.