title: Why am I getting 'One or more types required to compile a dynamic expression cannot be found.'?
body: <p>I had a project that I've updated from </p>
  
  <ul>
  <li>.NET 3.5  MVC v2  to</li>
  <li>.NET 4.0 MVC v3</li>
  </ul>
  
  <p>Compiling I get an error when I try to use or set the <code>@ViewBag.Title</code> property.</p>
  
  <blockquote>
    <p>One or more types required to compile a dynamic expression cannot be found. 
    Are you missing references to Microsoft.CSharp.dll and System.Core.dll?</p>
  </blockquote>
  
  <p>I have done the following</p>
  
  <ol>
  <li>Followed the <a href="http://www.asp.net/learn/whitepapers/mvc3-release-notes#upgrading" rel="noreferrer">upgrade steps</a></li>
  <li>Set the target framework in the Project/Properties/Application tab to <em>.NET Framwework 4</em></li>
  <li>Added the <em>System.Core</em> framework <a href="http://connect.microsoft.com/VisualStudio/feedback/details/525663/cannot-remove-system-core-dll-reference-from-a-vs2010-project" rel="noreferrer">manually</a></li>
  <li>Added the <em>Microsoft.CSharp</em> framework</li>
  <li>Added the <em>System.Xml</em> framework</li>
  <li>Added the <em>System.Xml.Linq</em> framework</li>
  <li>Made sure my <em>Web.Config</em> is correct (it gets written over by Web.Debug.Config, etc)</li>
  <li>Created the <em>model</em>, <em>controller</em> and a Razor <em>View</em></li>
  <li>Create a __Layout.cshtml_</li>
  </ol>
  
  <p>I'm at loss as to what else to do?</p>
  
  <p>EDIT:</p>
  
  <p>I notice in the GAC Gui there is System.Core 3.5.0.0 but no System.Core 4.0.0.0. Does this mean that its getting confused and is still using the previous version? Or am I misunderstanding the GAC?</p>
  
  <p>EDIT:</p>
  
  <p>My web.config looks as follows</p>
  
  <pre><code>...
  &lt;compilation debug="true"&gt;
      &lt;assemblies&gt;
          &lt;add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
          &lt;add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
          &lt;add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
          &lt;add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
      &lt;/assemblies&gt;
  &lt;/compilation&gt;
  ....
  &lt;pages&gt;
      &lt;controls&gt;
      &lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
  &lt;/controls&gt;
  &lt;namespaces&gt;
          &lt;add namespace="System.Web.Helpers" /&gt;
          &lt;add namespace="System.Web.WebPages"/&gt;
      &lt;add namespace="System.Web.Mvc" /&gt;
      &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
      &lt;add namespace="System.Web.Mvc.Html" /&gt;
          &lt;add namespace="System.Web.Routing" /&gt;
      &lt;add namespace="System.Linq" /&gt;
      &lt;add namespace="System.Collections.Generic" /&gt;
  &lt;/namespaces&gt;
  &lt;/pages&gt;
  ....
  </code></pre>