Click here to Skip to main content
15,881,616 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
i am wroking on a mvc 4 project where i wanted to call a mvc webapi
i get the above error when i run it.
the code bellow is from my mvc 4 web project

C#
private Discount GetMultibuyDiscount(MultibuyBag bag)
        {
            string uri = System.Configuration.ConfigurationManager.AppSettings["Next:Use:MultibuyServiceURI"];
            var client = new HttpClient();

            var response = client.PostAsJsonAsync(uri + "Post?timeout=2000", bag).Result; //92 //5683 .PostAsJsonAsync
            if (response.IsSuccessStatusCode)
            {
                return response.Content.ReadAsAsync<Discount>().Result;
            }

            Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            return new Discount();

        }


when it ready client.PostAsJsonAsync it break with the above error.
what i have done wrong
appreciate all your help
Posted
Updated 4-Jul-18 20:32pm
Comments
Jameel VM 29-Aug-13 9:40am    
i think your application expect the assembly system.net.http.formatting.Please add the assembly once and then try
rushdy20 29-Aug-13 10:17am    
i have add the add the assembly reference
Jason Gleim 29-Aug-13 10:26am    
Do you have any third-party controls or libraries in your project? This type of error usually happens when you have a dependency in a 3rd party control on a specific version of that assembly and your project references a different version of the same assembly.
rushdy20 29-Aug-13 10:42am    
not any thirdpay control but i add the assembly system.net.http.formatting from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5 to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 as my project is a mvc 4 project is that something which i sould not do ?
Aditya Bhargav Upadhyay 7-Aug-15 0:46am    
Can You got the solution for the same.

I have same Issue.

but In my local its working fine. I am getting this error on server

Please help

1 solution

I got the same issue in server but working fine in local.

Solution:

Go to Reference -> System.Net.Http.Formatting -> Right click -> properties.

Set Copy Local to True and Specific version to False.

That's it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900