Reputation: 790
Enabled CORS on one project, trying to do it on another existing project, however the "EnableCors" method cannot be found in during compilation:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableCors();
The exact compile fail error message is
'HttpConfiguration' does not contain a definition for 'EnableCors' and no extension method 'EnableCors' accepting a first argument of type 'HttpConfiguration' could be found (are you missing a using directive or an assembly reference)
I've done the same thing in this project as I have the other project:
<package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.3" targetFramework="net451" />
This project has odata in it though...I'm not sure if that's the major difference making it fail.
Any ideas? I've also tried
Update-Package -reinstall Microsoft.AspNet.WebApi.Cors
Upvotes: 9
Views: 8550
Reputation: 11
I had this situation today. Could not find the using libraries. Tried uniinstalling and reinstalling a couple of times Microsoft.AspNET.WebAPI.Cors as well as Asp.Net.Cors at v5.2.6. It would compile, but then after I published it showed that the references were lost again...very very odd indeed. So I took a shot and looked at the Updates in Nuget and one stood out. Microsoft.Net.Compilers. 2.8.2 and current was 2.9.0. Updated that one and tried again..boom worked. Clearly there is a dependency that caused some oddities, I don't begin to profess understanding of that quirk, but thought it might help someone out there.
Upvotes: 1
Reputation: 790
I had to reinstall all the packages - THEN the compile error went away.
Weird. I had built & cleaned the project several times.
Upvotes: 5