I upgraded my MVC application from MVC 3 to 5.2.2 and now I'm getting this error. I've made a brand new MVC project using the new project wizard and this works, and I've compared my /web.config and Views/web.config files across the two projects and don't see any differences that seem important.

Looking in the object browser, I see that there are in fact two different HtmlHelper objects defined in System.Web.WebPages and System.Web.Mvc, which seems relevant:

enter image description here

But I'm not sure what to do with this fact.

Make sure that your model points to a real class, but this is probably because the MvcWebPageRazorHost isn't registered or different versions are registered in the root web.config vs. the views web.config, often caused by updating MVC versions

I was getting several compiler errors anytime I opened a Razor View:

<!-- language: lang-none --> <pre><code><a href="https://msdn.microsoft.com/en-us/library/856b0w3t.aspx">Type '<i>System.Web.Mvc.WebViewPage</i>' is not defined.</a> <a href="https://msdn.microsoft.com/en-us/library/d3xk5aeb.aspx">'<i>Context</i>' is not declared. It may be inaccessible due to its protection level.</a> <a href="https://msdn.microsoft.com/en-us/library/c309sxx0.aspx">sub '<i>Execute</i>' cannot be declared '<i>Overrides</i>' because it does not override a sub in a base class.</a> <a href="https://msdn.microsoft.com/en-us/library/856b0w3t.aspx">'<i>Html</i>' is ambiguous, imported from the namespaces or types '<i>System.Web.WebPages</i>, <i>System.Web.Mvc</i>'.</a> </code></pre>

What fixed it was updating the webpages:Version in the web.config:

From This:

<!-- language-all: lang-xml --> <pre><code>&lt;add key=&quot;webpages:Version&quot; value=&quot;<b>2.0.0.0</b>&quot; /&gt; </code></pre> <pre><code>&lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.Helpers&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>2.0.0.0</b>&quot; newVersion=&quot;<b>2.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; &lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.Mvc&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>4.0.0.0</b>&quot; newVersion=&quot;<b>4.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; &lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.WebPages&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>2.0.0.0</b>&quot; newVersion=&quot;<b>2.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; </code></pre>

To This:

<pre><code>&lt;add key=&quot;webpages:Version&quot; value=&quot;<b>3.0.0.0</b>&quot; /&gt; </code></pre> <pre><code>&lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.Helpers&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>3.0.0.0</b>&quot; newVersion=&quot;<b>3.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; &lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.Mvc&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>5.0.0.0</b>&quot; newVersion=&quot;<b>5.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; &lt;dependentAssembly&gt; &lt;assemblyIdentity name=&quot;System.Web.WebPages&quot; publicKeyToken=&quot;31bf3856ad364e35&quot; /&gt; &lt;bindingRedirect oldVersion=&quot;1.0.0.0-<b>3.0.0.0</b>&quot; newVersion=&quot;<b>3.0.0.0</b>&quot; /&gt; &lt;/dependentAssembly&gt; </code></pre>