找不到类型或命名空间名称"dynamic"

G M*_*ros 5 .net c# asp.net json visual-studio-2010

Microsoft Visual Studio 2010 Ultimate(版本10.0.40219.1 SP1Rel).

Microsoft .NET Framework版本4.5.50709 SP1Rel

我正在编译.net framework 4.0.

每当我尝试使用动态或var数据类型时,我都会收到主题行中显示的错误:

找不到类型或命名空间名称"dynamic".

找不到类型或命名空间名称'var'.

我正在尝试使用JsonFX来解析从其他Web服务收到的数据.有时数据将代表"消息",有时它将代表"轨道".根据这个JsonFx文档,我应该能够按照"序列化到/从动态类型(.NET 4.0的默认值)"的示例:"

我在我的网站上添加了一个名为test的页面.下面的代码块来自Test.aspx.cs我试图使用的代码是这样的:

using System;
using System.Text;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JsonFx;
using JsonFx.Json;
using Microsoft.CSharp;

public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Data = "";
        Data = @"[{""meta"":{""account"":""orbitinte"",""event"":""track""},""payload"":{""id"":410827200397312213,""id_str"":""410827200397312213"",""asset"":""359551031717134"",""recorded_at"":""2013-02-07T15:59:04Z"",""received_at"":""2013-02-07T16:00:37Z"",""fields"":{}}},{""meta"":{""account"":""orbitinte"",""event"":""track""},""payload"":{""id"":410827200409895125,""id_str"":""410827200409895125"",""asset"":""359551031717134"",""recorded_at"":""2013-02-07T16:00:04Z"",""received_at"":""2013-02-07T16:00:37Z"",""fields"":{}}}]";
        Data = @"[{""meta"":{""account"":""orbitinte"",""event"":""message""},""payload"":{""id"":410865901198377173,""thread_id"":null,""parent_id"":410865891354345685,""id_str"":""410865901198377173"",""thread_id_str"":"""",""parent_id_str"":""410865891354345685"",""type"":""message"",""channel"":""com.mdi.services.adminProtocol"",""sender"":""359551031717134"",""recipient"":""@@server@@"",""asset"":""359551031717134"",""b64_payload"":""eyJlcnJvciI6ImNhbm5vdCBwYXJzZSBjb21tYW5kIn0="",""recorded_at"":""2013-02-07T18:34:25Z"",""received_at"":""2013-02-07T18:34:24Z""}}]";


        JsonReader Reader = new JsonReader();
        dynamic Output = Reader.Read(Data);

        Notifications oNotifications = new Notifications();
        oNotifications.ProcessNotifications(Data);
    }
}
Run Code Online (Sandbox Code Playgroud)

在web.config文件中:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v4.0"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>
Run Code Online (Sandbox Code Playgroud)

我是C#和asp.net的新手.但是我一直在寻找解决这个问题的方法.我看到的一切都提到了编译器版本和.net框架版本.我想我已经提供了所有相关细节,但是如果还有什么我应该添加到这个问题,请告诉我.

zim*_*nen 5

确保您Microsoft.CSharp在项目中有参考.

关于这个DLL的更多信息可以在这里找到.


Mat*_* M. 4

您的 IIS 网站是否配置为使用 .NET 2.0?我听起来就是这样。首先检查配置..您的测试在本地工作吗?

你的编译器应该是这样的:

<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Run Code Online (Sandbox Code Playgroud)

您的版本设置为 Version=2.0.0.0