2013-02-07 129 views
5

Microsoft Visual Studio 2010 Ultimate(版本10.0.40219.1 SP1Rel)。無法找到類型或名稱空間名稱'dynamic'

Microsoft .NET Framework版本4.5.50709 SP1Rel

我編譯到.NET框架4.0。

每當我嘗試使用動態或VAR數據類型,我得到在主題行中顯示的錯誤:

類型或命名空間名稱「動態」無法被發現。

無法找到類型或名稱空間名稱'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"":""@@[email protected]@"",""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

你確定你沒有任何愚蠢的錯誤一樣失蹤'using'報表?這個功能應該「開箱即用」。去年在C#店工作,我從未見過這個問題。 – evanmcdonnal

+0

我不這麼認爲,但我不確定。我只是修改了代碼塊以顯示使用語句。 –

+0

這是在一個班級或主要? – evanmcdonnal

回答

4

您的網站在配置爲使用.NET 2.0的IIS中嗎?這就是我聽起來的感覺。先檢查配置..你的測試在本地工作嗎?

你的編譯器應該是這樣的:

<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

+0

運行期間,Environment.Version報告4.0.30319.18034 –

+0

我做了您所建議的更改,並沒有什麼區別。 –

+0

當您訪問該頁面時,您獲得的實際錯誤是什麼?在IIS中,在AppPool部分下(我認爲)你是否確認下拉列表設置爲.NET 4?你在VS或IIS上運行這個嗎?你使用VS還是IIS express運行?您是否在項目屬性屏幕上驗證了您實際上是以.NET 4爲目標的? –

5

請確保您在項目中參考了Microsoft.CSharp

有關此DLL的更多信息可以找到here

+0

這很可能是問題 - 使用'dynamic'關鍵字隱含地依賴於這個程序集。 – JerKimball

+0

我原本沒有在我的項目中引用Microsoft.CSharp。我添加了它,並沒有幫助。我還在代碼文件中添加了「使用Microsoft.CSharp」,但仍然出現錯誤。 –

+0

我剛剛重啓IDE,希望它能解決問題,但事實並非如此。 –

相關問題