1

I have recently updated my project from Mvc 3 to Mvc 5 and we are trying to publish the app on an IIS server so that we may test it. But we have a nasty crash that always occurs and I do not know what provokes it and how to correct it.

Here's the stack trace:

Server Error in '/' Application.

Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
  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.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.



=== Pre-bind state information ===
LOG: DisplayName = System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/MyApp/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\MyApp\bin
Calling assembly : System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\MyApp\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: The same bind was seen before, and was failed with hr = 0x80070002.



Stack Trace: 



[FileNotFoundException: Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +0

[InvalidOperationException: The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12969195
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12968904
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +280
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12968244
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12807949




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

So what puzzles me is that we do not have the System.Web.Razor packaged installed anymore. Rather, we have the System.Web.Razor version 3.0.0.0. Nonetheless, I have done everything suggested in this link on how to upgrade from mvc3 to mvc4 and all my packages are up-to-date.

I even tried to uninstall the Microsoft.Web.WebPages.OAuth package to see if it was the cause, but it is more resistant than a cockroach and I could not delete it without having an app that did not compile anymore. I need help resolving this case, my only next option would be to try to create a new app and reload all the stuff, which is kinda long and tedious.

hsim
  • 2,000
  • 6
  • 33
  • 69
  • Since you've already added assembly redirects to web.config and it did not work for you it looks like you idea to try to create new app to compare 2 is good plan. – Alexei Levenkov Jun 10 '14 at 16:17
  • I'd like to explore all avenues before going to such an extreme, especially since both dll are up-to-date but `Microsoft.Web.WebPages.OAuth` only refers to an old dll... – hsim Jun 10 '14 at 17:13
  • Actually it *does not* look like you've added assembly redirect for System.Web.Razor based on Fusion log you've posted. I guess it is your problem. – Alexei Levenkov Jun 10 '14 at 17:26
  • Ok. Could you provide an example? – hsim Jun 10 '14 at 17:32
  • There are plenty in article you've linked to in the post (for different assemblies, but idea is the same). Feel free to search for "assembly version redirect" to find MSDN articles. – Alexei Levenkov Jun 10 '14 at 17:33
  • I have an assembly redirect for `System.Web.Razor`, now I'll try to add one to `Microsoft.Web.WebPages.Razor` and see where it leads. – hsim Jun 10 '14 at 17:42

2 Answers2

1

this could be due to assembly mismatch. you have to update Views\Web.config file with updated assembly for razor.

Amit Kumar
  • 11
  • 6
1

Finally had to reinstall the whole things.

Following this link: No ASP.NET MVC 5 Web Application Template on VS 2012?, I have reintegrated everything, remade the packages, and now it works.

Community
  • 1
  • 1
hsim
  • 2,000
  • 6
  • 33
  • 69