Microsoft Visual Studio 2010 Ultimate (バージョン 10.0.40219.1 SP1Rel)。
Microsoft .NET Framework バージョン 4.5.50709 SP1Rel
.net Framework 4.0 にコンパイルしています。
dynamic または var データ型を使用しようとすると、件名に次のエラーが表示されます。
タイプまたは名前空間名「dynamic」が見つかりませんでした。
タイプまたはネームスペース名「var」が見つかりませんでした。
JsonFX を使用して、別の Web サービスから受け取ったデータを解析しようとしています。with data は「メッセージ」を表す場合もあれば、「トラック」を表す場合もあります。この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 フレームワークのバージョンについて言及しています。関連するすべての詳細を提供したと思いますが、この質問に追加する必要がある場合はお知らせください。