I'm getting an error in Visual Studio 2015
I was using windows 8.1 and visual studio 2013 and all projects with asp.net MVC 5 were working and developing fine without any error.
Since I installed windows 10 and visual studio 2015 my whole ASP.NET MVC 5 project doesn't work well.
I created new default template in visual studio 2015 to check them. I got the same error on those new project also.
I get errors as :
CS0234 The type or namespace name 'Mvc' does not exist in the
namespace 'Microsoft.AspNet' (are you missing an assembly reference?)
And
The name "Layout" doesn't exist in current context.
**Things I have already Tried: **
- Repaired VS 2015.
- Uninstalled and installed Install-Package Microsoft.AspNet.Mvc from Nuget
- Copy Local = True
- System.web.MVC already referenced.
- The version of web.config all places 5.2.3.0
I was getting this error in %AppData%\Microsoft\VisualStudio\14.0\ActivityLog.xml:
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'RazorSupportedRuntimeVersion' Key being added: 'RazorSupportedRuntimeVersion'
 at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
 at System.Collections.Hashtable.Add(Object key, Object value)
 at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value)
 at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property)
 at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer)
 at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version& razorVersion)
 at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer)

I ran C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\Common7\IDE\devenv.exe /resetuserdata and it was fixed.
Taken from Exception when opening a cshtml file
I followed these steps in order to completely re-install Visual Studio 2015 which solved the problem. Repair didnt work
run the command
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\devenv.exe /resetuserdata
Downloaded the web installer setup file and run the following command in the downloaded directory
vs_community.exe /uninstall /force
After Uninstalling i made sure no file software related to VS is installed and restarted PC
- Installed new Visual Studio using Web Installer.
Run the command again.
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\devenv.exe /resetuserdata
Updates were available inside Visual Studio , installed them - Restarted Visual Studio
Now open any asp.net mvc solution it takes time though in start but after that it works.
I have the same problem with Visual Studio 2015, every time I open my ASP.NET 5.0 project I get that error, But when I re-open the application again, the errors go away.
By the way the problem seems about correct versioning for example if you are using the Beta 7.0 of ASP.NET 5.0, maybe some packages still use previous versions like Beta 5.0,...
I've run into this error and was able to resolve it with an edit to the runtime/assemblyBinding
section of the web.config, as follows:
<!-- Original //-->
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<!-- Changed to... //-->
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
This may be in the main web.config
file and/or the one in the Views directory
Hope this helps!