Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Applications break after Windows update of Oct 15

This morning I woke up discovering that my MVC 4 web application on my server had broken.

The error message is:

An exception of type 'System.IO.FileNotFoundException' occurred in 
mscorlib.dll but was not handled in user code.
Additional information: Could not load file or assembly 
'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, 
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 
The system cannot find the file specified.

I opened my VS project and ran it from code (so on a different computer), same error occurred!

I checked my server log and discovered updates were automatically installed at 5:06 AM. One of the updates was done by an installer package AspNetMVC4.msi. One minute later, the first errors on my web application began streaming in.

On my development laptop, the same installer had run yesterday (Oct 15) at 1:10:10 PM.

Same problem on both computers.

I had never heard of Newtonsoft.Json (but now I found out what it is). It looks as if one of the MVC dlls (unlikely) or one of the package dlls (more likely) has a reference to Newtonsoft.

I have tried to intall Newtonsoft from nuget. This did have some effect, the error changed from FileNotFound to a FileLoadException:

An exception of type 'System.IO.FileLoadException' occurred in 
mscorlib.dll but was not handled in user code Additional
information: Could not load file or assembly 'Newtonsoft.Json,   
Version=4.5.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)

I also tried to upgrade from .NET 4.5 to 4.5.1. That did not help.

BTW, the error occurs in RegisterRoutes in Global.asax.cs:

routes.MapHttpRoute( 
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

Any ideas?

like image 979
Jan DeCoder Avatar asked Oct 16 '14 07:10

Jan DeCoder


1 Answers

Thanks all for your good thoughts! I had tried to do the assembly redirect, but it didn't work.

I eventually fixed the problem in a very simple way. I suddenly realized I never used the route below:

routes.MapHttpRoute( 
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

So I deleted these lines and presto, all worked again!

Some research showed me the MapHttpRoute is part of the older version of the System.Web.Mvc.dll, but not of the newer version. So the new dll is incompatible with the older version.

It still bothers me that a running, production web application breaks while I am sleeping by a Windows update. Turning off Windows updates could be a solution, but makes the server more vulnerable... what is wisdom here.

Thanks again everyone.

like image 56
Jan DeCoder Avatar answered Nov 07 '22 14:11

Jan DeCoder