26

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.

Community
  • 1
  • 1
Simon Legg
  • 889
  • 1
  • 8
  • 11
  • 1
    I had the same problem recently and finally solved it, check [my solution on stackoverlow](http://stackoverflow.com/questions/36125730/razor-views-show-warnings-cs1702-after-upgrading-to-microsoft-aspnet-mvc-version) – rekna Mar 26 '16 at 15:29

8 Answers8

17

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.

Brian Merrell
  • 1,144
  • 14
  • 20
  • 3
    In my case I also had to restart Visual Studio to get rid of those messages – Piotrek Jan 19 '17 at 10:50
  • This is the best answer to the question if you are seeing this error popup "out of the blue" on established solutions. – bri Apr 25 '18 at 12:23
10

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.

Simon Legg
  • 889
  • 1
  • 8
  • 11
  • 2
    what do you mean "update MVC package"? it wil require a lot of tests... is it possible do not update it and fix the problem? – serge Oct 23 '15 at 13:38
  • If there is a desire to update: then updating the package doesn't for some reason update the web.config files, which caused me a problem. Hence the additional step of find/replace. – Simon Legg Oct 26 '15 at 08:45
  • 1
    @SimonLegg I updated all packages and restarted, it works fine. – Arun Prasad E S Dec 30 '16 at 18:02
  • 1
    @ARUNEdathadan - In that case my issue could have been something else - maybe clearing NuGet cache as per Brian Merrel's answer might of solved it. – Simon Legg Jan 03 '17 at 09:10
1

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.

Joao Ricardo
  • 311
  • 3
  • 6
0

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"
Jurgy
  • 2,128
  • 1
  • 20
  • 33
0

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.

Babak
  • 1,274
  • 15
  • 18
0

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.

Adesola
  • 1
  • 1
  • 2
-1

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.

Jan Jurníček
  • 126
  • 1
  • 5
-2

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.

Eric
  • 21
  • 2
  • 10
    MvcBuildViews = true helps catch errors at compile time instead of runtime. Setting it to false simply means your views aren't type checked and any errors won't show up until runtime. – Tikall May 03 '18 at 08:29