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 Documentation,我应该能够按照“序列化到/从动态类型(.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);
}
}
在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>
我是C#和asp.net的新手。但是我一直在寻找解决这个问题的方法。我看到的一切都提到了编译器版本和.net框架版本。我想我已提供了所有相关细节,但如果还有其他问题我应该加入这个问题,请告诉我。
答案 0 :(得分:5)
确保您在项目中引用Microsoft.CSharp
。
可以找到关于此DLL的更多信息here。
答案 1 :(得分: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">
您的设置为版本= 2.0.0.0