Razor View Reference Error: FileNotFoundException

0

I just got to fix the old project from other guys which use visual studio 2012. I think it was built on MVC4 because it still uses WebMatrix.Data and WebMatrix.WebData. Because I don't have that vs version so I was using visual studio 2013 community edition and run install-package update. After couple fixes, I got this problem when I tried to run it. The following is the error messages:

    Server Error in '/' Application.
    Could not load file or assembly 'System.Web.Razor, Version=3.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=3.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=3.0.0.0, Culture=neutral,     
    PublicKeyToken=31bf3856ad364e35' could not be loaded.

    === Pre-bind state information ===
    LOG: DisplayName = System.Web.Razor, Version=3.0.0.0, Culture=neutral, 
    PublicKeyToken=31bf3856ad364e35
    (Fully-specified)

    LOG: Appbase = file:///D:/BitBucketGit/DirtOilGas.Website/
    LOG: Initial PrivatePath = D:\BitBucketGit\DirtOilGas.Website\bin

    Calling assembly : System.Web.WebPages.Razor, Version=3.0.0.0, 
    Culture=neutral, PublicKeyToken=31bf3856ad364e35.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: D:\BitBucketGit
    \DirtOilGas.Website\web.config
    LOG: Using host configuration file: C:\Users\amie\Documents\IISExpress
    \config\aspnet.config

    LOG: Using machine configuration file from C:\Windows\Microsoft.NET
    \Framework\v4.0.30319\config\machine.config.
    LOG: Post-policy reference: System.Web.Razor, Version=3.0.0.0, 
    Culture=neutral, PublicKeyToken=31bf3856ad364e35
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET
    /Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a
    /System.Web.Razor.DLL.

    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET
    /Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a
    /System.Web.Razor/System.Web.Razor.DLL.

    LOG: Attempting download of new URL file:///D:/BitBucketGit
    /DirtOilGas.Website/bin/System.Web.Razor.DLL.

    LOG: Attempting download of new URL file:///D:/BitBucketGit
    /DirtOilGas.Website/bin/System.Web.Razor/System.Web.Razor.DLL.
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET  
    /Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a    

    /System.Web.Razor.EXE.

    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET  
    /Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a   
    /System.Web.Razor/System.Web.Razor.EXE.

    LOG: Attempting download of new URL file:///D:/BitBucketGit   
    /DirtOilGas.Website/bin/System.Web.Razor.EXE.

     LOG: Attempting download of new URL file:///D:/BitBucketGit
     /DirtOilGas.Website/bin/System.Web.Razor/System.Web.Razor.EXE.


Stack Trace:


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


    [InvalidOperationException: The pre-application start initialization method 
    Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception 
    with the following error message: Could not load file or assembly 
    'System.Web.Razor, Version=3.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) +547
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 
   methods) +132

   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String 
   preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager 
   appManager, IApplicationHost appHost, IConfigMapPathFactory 
   configMapPathFactory, HostingEnvironmentParameters hostingParameters, 
   PolicyLevel policyLevel, Exception appDomainCreationException) +521


   [HttpException (0x80004005): The pre-application start initialization method 
   Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception  
   with the following error message: Could not load file or assembly 
   'System.Web.Razor, Version=3.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) +9930508
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest 
   wr, HttpContext context) +254

    Server Error in '/' Application.
Could not load file or assembly 'System.Web.Razor, Version=3.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=3.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=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///D:/BitBucketGit/DirtOilGas.Website/
LOG: Initial PrivatePath = D:\BitBucketGit\DirtOilGas.Website\bin
Calling assembly : System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\BitBucketGit\DirtOilGas.Website\web.config
LOG: Using host configuration file: C:\Users\amie\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a/System.Web.Razor.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a/System.Web.Razor/System.Web.Razor.DLL.
LOG: Attempting download of new URL file:///D:/BitBucketGit/DirtOilGas.Website/bin/System.Web.Razor.DLL.
LOG: Attempting download of new URL file:///D:/BitBucketGit/DirtOilGas.Website/bin/System.Web.Razor/System.Web.Razor.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a/System.Web.Razor.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/86bf6c81/eeee762a/System.Web.Razor/System.Web.Razor.EXE.
LOG: Attempting download of new URL file:///D:/BitBucketGit/DirtOilGas.Website/bin/System.Web.Razor.EXE.
LOG: Attempting download of new URL file:///D:/BitBucketGit/DirtOilGas.Website/bin/System.Web.Razor/System.Web.Razor.EXE.


Stack Trace:


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

[InvalidOperationException: The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.Razor, Version=3.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) +547
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

[HttpException (0x80004005): The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.Razor, Version=3.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) +9930508
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
asp.net-mvc
visual-studio
webmatrix-2
asked on Stack Overflow Apr 1, 2015 by John Hadikusumo • edited May 3, 2019 by Cœur

1 Answer

0

Manual solution findings may take time. Just Right click project and click 'Manage Nuget Packages' , search 'Microsoft ASP.NET Razor' and install version 3.2.3. it will update required assemblies and references. Hope it will help you.

answered on Stack Overflow Apr 1, 2015 by Bhawesh Paliwal

User contributions licensed under CC BY-SA 3.0