Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC WebApi - System.MissingMethodException : Method not found: 'Void System.Net.Http.ObjectContent

I updated to the final version of MVC4 and now my tests are failing with this error:

System.MissingMethodException : Method not found: 'Void System.Net.Http.ObjectContent`1..ctor(!0, System.Net.Http.Formatting.MediaTypeFormatter, System.Net.Http.Headers.MediaTypeHeaderValue)'. 
at System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration)

On my unit test I have (it was working with RC version):

var configuration = new HttpConfiguration(); 
var request = new HttpRequestMessage(); 
var controller = ClassUnderTest; 
controller.Request = request; 
controller.Request.Properties["MS_HttpConfiguration"] = configuration;

When I run my test I have the exception on this line of code inside the controller:

return Request.CreateResponse(HttpStatusCode.Created, myObj);

I tried different things but I could not fix the tests. Any ideas?

like image 756
Daniele Avatar asked Jan 22 '26 07:01

Daniele


1 Answers

I solved the problem and it was quite simple.

I unistalled the NuGet packages relative to the RC version and installed the the new one. This solve the problem

like image 67
Danielone Avatar answered Jan 23 '26 23:01

Danielone