3
votes

I created MVC 4 application with Web API. It works good in local environment. When I deployed it to Azure, it gives following error.

Exception information: Exception type: HttpException Exception message: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() at System.Web.Http.HttpConfiguration.DefaultFormatters(HttpConfiguration config) at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) at System.Web.Http.GlobalConfiguration.b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at System.Web.Http.GlobalConfiguration.get_Configuration() at System.Web.Http.GlobalConfiguration.Configure(Action1 configurationCallback) at Activity.Web.Monitor.UI.MvcApplication.Application_Start()

Any idea how to resolve this?

2

2 Answers

1
votes

It says "The located assembly's manifest definition does not match the assembly reference" because CLR found another version of Newtonsoft.json while it was looking for ver 6.0.

This happens because your application is referencing another version of Newtonsoft.Json and some other dependency on the application uses version 6.0 of Newtonsoft.json. If you drill down through the .cspkg (use 7zip) and extract the Newtonsoft.json from siteroot\0\bin, you will get to know which version of Newtonsoft is included on the package.

Verify on the project references to see if CopyLocal is set to true or not for Netonsoft.json. Also, on web.config, add an assembly redirection to make sure call for any older version of Newtonsoft.json gets redirected to required version.

1
votes

Probably in your solution there is another version of Newtonsof.json. You need to delete your neftonsoft.json file and replace it with the right veersion (6.0.0.0)