I am having a problem with a project with Web API.
Inside of the global.asax file I have this and it is giving an error that says
An exception of type 'System.TypeLoadException' occurred in System.Web.Http.WebHost.dll but was not handled in user code
Additional information: Inheritance security rules violated while overriding member: 'System.Web.Http.WebHost.Routing.HostedHttpRoute.get_RouteTemplate()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
On this line
RouteTable.Routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{id}", defaults:=New With { _
Key .id = RouteParameter.[Optional] _
})
I upgraded some packages. This used to be my packages.config file
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net45" />
They are now upgraded to this:
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
Any idea why I just started getting this error after upgrading?
Thank you very much!
I have project A that references project B. In project B there are controllers and there I am calling RouteTable.Routes.MapHttpRoute for these controllers.
I have found in my case that problem was that in project A WebApi NuGet package version was higher than in referenced project B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With