I'm getting the CA2000 error on all my Wep Api 2 controllers for the Options() verb.
In method 'PromotionController.Options()', object '<>g__initLocal0' is not disposed along all exception paths.
I need to support pre-flight requests made for cross domain ajax calls so all I'm doing is returning a HttpStatusCode.Ok
so that the subsequent post/put/delete will fire off.
public HttpResponseMessage Options()
{
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
}
I have tried the using statement like this:
public HttpResponseMessage Options()
{
using(var response = new HttpResponseMessage())
{
response.StatusCode = HttpStatusCode.OK;
return response;
}
}
but when I hit it with an Options request from Postman I get an exception:
Cannot access a disposed object.\r\nObject name: 'System.Net.Http.HttpResponseMessage'.
How do I return the HttpStatusCode.Ok
in a way that it won't throw Code Analysis errors?
Thanks!