25
votes

With reference to questions/26393157/windows-update-caused-mvc3-and-mvc4-stop-working. The quickest way to resolve the warning below?

Assuming assembly reference 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy.

8
I had the same problem recently and finally solved it, check my solution on stackoverlowrekna

8 Answers

16
votes

I've had this happen with my NuGet packages every once in a while. I haven't been able to identify exactly how it happens. (I assume user error.) I didn't need to upgrade anything to solve it, just clear the NuGet cache:

I use the nuget command line tool found here.

You can clear all caches with this command:

nuget locals all -clear

See: https://docs.nuget.org/consume/command-line-reference

You'll probably need to restart Visual Studio if it is open.

10
votes

As per the best answer to the question....

  • Update MVC package (Visual Studio > Right click project/solution > manage nuget packages > Updates > Microsoft ASP.NET MVC > Update)
  • Manually add the compilation assembly

but then

  • Find - System.Web.Mvc, Version=4.0.0.0
  • and replace with - System.Web.Mvc, Version=4.0.0.1

Which will find all the hidden references in the Views/Web.config files.

1
votes

Every time I have had this issue I always start by doing a rebuild which will clear your bin folder. You likely do not need to close and open visual studio, as I never have, and it should work.

If this doesn't work then try more complicated solutions like those above but this could be a quick, clean fix.

0
votes

I was getting this warning in RoslynPad because one of the dll's I was referencing (for me it was mscorlib.dll) used a different version than the retrieved version via NuGet. As the warning states, you can solve it with solve it with a runtime policy with a link to the dll of the version you want to be using. Just add something like this to the top of your file:

#r "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll"
0
votes

Sorry for the late reply but in my case this warning was showing up because I was using different versions of Microsoft.AspNet.Mvc across my Visual Studio solution. I was able to get rid of it by upgrading the older packages to the same version.

Hope this helps someone.

0
votes

What worked for me after trying severally is to update application insights and all packages from NuGet. Then I ensured that there were no version conflicts on the App insights and it worked fine.

-1
votes

Don't refer NuGet Package Components and interfaces directly from your cshtml code. Instead, write your own components, extesion methods and view models referencing them from plain C# code placed in cs files. First, then you wouldn't obtain CS1702 warning. And secondly, this will facilitate future migrations to newer versions of the NuGet package or even another package: All necessary fixes will be shown you by the compiler.

This is probably the desired change in your run-time policy.

-2
votes

After tested all propositions, I finally succeeded to get rid of the warning by editing the .csproj of my web application and set the property MvcBuildViews to false.

Maybe this could help some of you.