9
votes

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: **

  1. Repaired VS 2015.
  2. Uninstalled and installed Install-Package Microsoft.AspNet.Mvc from Nuget
  3. Copy Local = True
  4. System.web.MVC already referenced.
  5. The version of web.config all places 5.2.3.0
4
Reopening the project solves your problem.Sirwan Afifi
i have tried reopening and unloading and loading project but still im getting that errorShan Khan

4 Answers

4
votes

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. ---&gt; System.ArgumentException: Item has already been added. Key in dictionary: &apos;RazorSupportedRuntimeVersion&apos;  Key being added: &apos;RazorSupportedRuntimeVersion&apos;&#x000D;&#x000A;   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)&#x000D;&#x000A;   at System.Collections.Hashtable.Add(Object key, Object value)&#x000D;&#x000A;   at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value)&#x000D;&#x000A;   at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property)&#x000D;&#x000A;   at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer)&#x000D;&#x000A;   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version&amp; razorVersion)&#x000D;&#x000A;   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer)&#x000D;&#x000A; 

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

3
votes

I followed these steps in order to completely re-install Visual Studio 2015 which solved the problem. Repair didnt work

  1. run the command

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /resetuserdata

  2. Downloaded the web installer setup file and run the following command in the downloaded directory

    vs_community.exe /uninstall /force

  3. After Uninstalling i made sure no file software related to VS is installed and restarted PC

  4. Installed new Visual Studio using Web Installer.
  5. Run the command again.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /resetuserdata

  6. Updates were available inside Visual Studio , installed them - Restarted Visual Studio

  7. Now open any asp.net mvc solution it takes time though in start but after that it works.

1
votes

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,...

0
votes

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!