Weird Error Upgrading ASP.NET MVC from 4 to 5

Eric Brown - Cal

I'm converting my project from MVC 4 to MVC 5 (and .Net 4 to .Net 4.5.2, which is the real driver of the changes.)

When I run one of my pages I get this error (blank space added by me for easier reading)

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection.

Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.

Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\studentportal3g\2204bad2\aece9b3b\assembly\dl3\ad80387c\91adbf51_fc73d101\System.Web.WebPages.Razor.dll'.

When I first saw this is though, Ah easy! Not so much :)

I've gone over every project and made sure it's version is upgraded to MVC 5 which has the 3.0.0.0 version of System.Web.WebPages.Razor.dll.

Clean rebuild, still get the error. No problem , I'll delete the cached temp files.

Clean rebuild, still get the problem. I go back, manually check each version of System.Web.WebPages.Razor.dll, in the references of each project that has a reference to it. I check my folder where I copy dlls to make references to them manually, it's not there.

If my solution doesn't' contain a copy of the DLL or a reference to the DLL, and I've manually deleted the cache folders in 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET

Files\studentportal3g...

Where is the old bad dll coming from? How do I fix this error? How do I prevent it happening again?

Thanks,

Eric-

NightOwl888

Visual Studio is a great tool, but it doesn't always make the right choices when it comes to upgrading dependencies, nor does it support every possible option available in MSBuild. Whenever you find yourself in a bind such as this you should manually review and (if necessary) edit your .csproj file in order to resolve it.

The problem isn't that your file exists in the GAC or that it has not been installed by NuGet, the issue is most likely that one of your project files still has a reference to the old version of System.Web.WebPages.Razor version 1.0.0.0, and you need to find all references to it and change them to 3.0.0.0 accordingly.

  1. Right-click on your project node in Solution Explorer and click Unload Project.
  2. Right-click the project node again and click Edit <projectName>.csproj.
  3. Search the file for references to System.Web.WebPages.Razor and update the version and the HintPath accordingly (as shown below). Make sure the HintPath you use actually points to an existing file.
  4. Repeat these steps for all dependent projects in the solution (and any that are in DLLs that are not part of the solution).

Old Reference

<Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Private>True</Private>        
    <HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

Updated Reference

<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

You should also go through the web.config and /Views/web.config files to ensure that they are not referencing any old versions of this assembly.

NOTE: If the above instructions don't solve your issue, the issue likely is outside of your solution. Most likely there is a 3rd party library that is referencing the old version of the file somewhere. If so, you could attempt to get an updated version of the DLL.

You may also want to check out this question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error Upgrading from ASP.NET 5 Beta 4 to Beta 5

From Dev

upgrading from MVC4 to MVC5

From Dev

ASP.NET MVC 5 error handling

From Dev

Redirect Error in ASP.NET MVC 5

From Dev

Model error in ASP.NET MVC 5

From Dev

Where is Filters folder in ASP .NET MVC 5 solution known from MVC 4

From Dev

No Intellisense in views updating from ASP.NET MVC 4 to MVC 5

From Dev

ASP.NET 5 (vNext) web project: library conflict upgrading from beta4 to beta6

From Dev

ASP.NET MVC 4 FileResult - In error

From Dev

Upgrade from Zurb Foundation 4 to 5 in ASP.NET MVC4.

From Dev

Upgrade from Zurb Foundation 4 to 5 in ASP.NET MVC4.

From Dev

Is asp.net 5 different from asp.net mvc?

From Dev

How to resolve nuget DLL hell after upgrading to ASP.NET MVC 5 and Web API 2

From Dev

How to resolve nuget DLL hell after upgrading to ASP.NET MVC 5 and Web API 2

From Dev

ASP.NET MVC 5 calling controller method from Javascript Error

From Dev

ASP.Net MVC 4 Areas not registering. HTTP 404 error from Visual Studio 2012

From Dev

Connection Strings error from the Web.config File in asp.net mvc4

From Dev

Error when migrating from asp net 5 to asp net core

From Dev

Make T4MVC work with ASP.NET 5

From Dev

Setup ASP.NET MVC 4 or 5 project with Angular 2

From Dev

Setup ASP.NET MVC 4 or 5 project with Angular 2

From Dev

Weird JavaScript error when using ASP.NET MVC bundling and minification

From Dev

Weird JavaScript error when using ASP.NET MVC bundling and minification

From Dev

weird swift error after upgrading from 1.1 to 1.2

From Dev

Event and error logging in Asp.net MVC 5 project

From Dev

ASP.NET MVC 5 Custom Error Page

From Dev

HTTP Error 403.14 in ASP.NET5 MVC6

From Dev

Confused with error handling in ASP.net 5 MVC 6

From Dev

The resource cannot be found (Error in ASP.NET MVC 5)

Related Related

  1. 1

    Error Upgrading from ASP.NET 5 Beta 4 to Beta 5

  2. 2

    upgrading from MVC4 to MVC5

  3. 3

    ASP.NET MVC 5 error handling

  4. 4

    Redirect Error in ASP.NET MVC 5

  5. 5

    Model error in ASP.NET MVC 5

  6. 6

    Where is Filters folder in ASP .NET MVC 5 solution known from MVC 4

  7. 7

    No Intellisense in views updating from ASP.NET MVC 4 to MVC 5

  8. 8

    ASP.NET 5 (vNext) web project: library conflict upgrading from beta4 to beta6

  9. 9

    ASP.NET MVC 4 FileResult - In error

  10. 10

    Upgrade from Zurb Foundation 4 to 5 in ASP.NET MVC4.

  11. 11

    Upgrade from Zurb Foundation 4 to 5 in ASP.NET MVC4.

  12. 12

    Is asp.net 5 different from asp.net mvc?

  13. 13

    How to resolve nuget DLL hell after upgrading to ASP.NET MVC 5 and Web API 2

  14. 14

    How to resolve nuget DLL hell after upgrading to ASP.NET MVC 5 and Web API 2

  15. 15

    ASP.NET MVC 5 calling controller method from Javascript Error

  16. 16

    ASP.Net MVC 4 Areas not registering. HTTP 404 error from Visual Studio 2012

  17. 17

    Connection Strings error from the Web.config File in asp.net mvc4

  18. 18

    Error when migrating from asp net 5 to asp net core

  19. 19

    Make T4MVC work with ASP.NET 5

  20. 20

    Setup ASP.NET MVC 4 or 5 project with Angular 2

  21. 21

    Setup ASP.NET MVC 4 or 5 project with Angular 2

  22. 22

    Weird JavaScript error when using ASP.NET MVC bundling and minification

  23. 23

    Weird JavaScript error when using ASP.NET MVC bundling and minification

  24. 24

    weird swift error after upgrading from 1.1 to 1.2

  25. 25

    Event and error logging in Asp.net MVC 5 project

  26. 26

    ASP.NET MVC 5 Custom Error Page

  27. 27

    HTTP Error 403.14 in ASP.NET5 MVC6

  28. 28

    Confused with error handling in ASP.net 5 MVC 6

  29. 29

    The resource cannot be found (Error in ASP.NET MVC 5)

HotTag

Archive