Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

c# - Why am I getting 'One or more types required to compile a dynamic expression cannot be found.'?

I had a project that I've updated from

  • .NET 3.5 MVC v2 to
  • .NET 4.0 MVC v3

Compiling I get an error when I try to use or set the @ViewBag.Title property.

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?

I have done the following

  1. Followed the upgrade steps
  2. Set the target framework in the Project/Properties/Application tab to .NET Framwework 4
  3. Added the System.Core framework manually
  4. Added the Microsoft.CSharp framework
  5. Added the System.Xml framework
  6. Added the System.Xml.Linq framework
  7. Made sure my Web.Config is correct (it gets written over by Web.Debug.Config, etc)
  8. Created the model, controller and a Razor View
  9. Create a __Layout.cshtml_

I'm at loss as to what else to do?

EDIT:

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?

EDIT:

My web.config looks as follows

...
<compilation debug="true">
    <assemblies>
        <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>
</compilation>
....
<pages>
    <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
<namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.WebPages"/>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
    <add namespace="System.Linq" />
    <add namespace="System.Collections.Generic" />
</namespaces>
</pages>
....
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For what it's worth, when this happened to me (in a project converted automatically from MVC2 to MVC3), all I had to do was add a project reference to Microsoft.CSharp. In my case the web.config already had the 4.0 references mentioned here, I assume courtesy of the upgrade script.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...