Trying with ... HttpConfiguration ... method to access method ... DefaultFormatters ... failed

I get the following error after doing some restructuring of the project, and I can't bend down where the problem is.

Server Error in '/' Application.
Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MethodAccessException: Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.

Source Error:


Line 15:          routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );
Line 16: 
Line 17:          routes.MapHttpRoute(
Line 18:              name: "DefaultApi",
Line 19:              routeTemplate: "api/{controller}/{action}",


Source File: c:\Dev\MyProject\Branches\Phase.2.3-Sprint 16\Client\ManagementSite\App_Start\RouteConfig.cs    Line: 17

Stack Trace:


[MethodAccessException: Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.]
   System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) +53
   System.Web.Http.GlobalConfiguration.<.cctor>b__0() +54
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   System.Web.Http.GlobalConfiguration.get_Configuration() +27
   System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults, Object constraints, HttpMessageHandler handler) +67
   System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults) +18
   MyProjectManagementSite.RouteConfig.RegisterRoutes(RouteCollection routes) in c:\Dev\MyProject\Branches\Phase.2.3-Sprint 16\Client\ManagementSite\App_Start\RouteConfig.cs:17
   MyProjectManagementSite.MvcApplication.Application_Start() in c:\Dev\MyProject\Branches\Phase.2.3-Sprint 16\Client\ManagementSite\Global.asax.cs:26

[HttpException (0x80004005): Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9905705
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9885060
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34009 

I linked all projects to .Net 4.5 and installed Newtonsoft Json.Net in 6.0.1 in all directions (instead of 6.0.7, which is the last one). When I create my web project, I get a warning “Conflicts found between different versions of the same dependent assembly” and if I run some borrowed code to list these potential conflicts, it looks like between Newtonsoft versions 4.5 and 6.0 there may be a conflict:

Possible conflicts for System.Net.Http:
System.Net.Http.Formatting references System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.ServiceModel       references System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Web.Http           references System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Web.Http.WebHost   references System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
MyProjectManagementSite  references System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
MyProjectManagementSite  references System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Possible conflicts for Newtonsoft.Json:
System.Net.Http.Formatting references Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
System.Web.Http           references Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
MyProject.Base           references Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
MyProjectManagementSite  references Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

Does this indicate a probable cause above and how to resolve it?

+4
source share
2

WebApi ( Nuget), .

+6

, , ​​ Microsoft.AspNet.WebApi.WebHost

+1

Source: https://habr.com/ru/post/1569991/


All Articles