2015-08-03 381 views
2

我正在開發一個需要SMS網關服務的應用程序。我們公司使用Plivo服務。我沿着sample code。 當我試圖建立的解決方案,我收到兩個錯誤:'RestSharp.IRestResponse`1 <T0>'在沒有引用的程序集中定義

錯誤1:The type 'RestSharp.IRestResponse'1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'RestSharp, Version=105.1.0.0, Culture=neutral, PublicKeyToken=null'

錯誤2:Cannot implicitly convert type 'RestSharp.IRestResponse'1<Plivo.API.MessageResponse>' to 'RestSharp.IRestResponse<Plivo.API.MessageResponse>'

我不明白這些錯誤的原因,因爲我安裝Plivo和RestSharp API的通過NuGet,並可以在解決方案資源管理器中看到dll。 第二個錯誤更令我困惑,因爲奇怪的類型'RestSharp.IRestResponse'1

如果有人能就這個問題提出建議,我會非常感激。

我的源代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using RestSharp; 
using Plivo.API; 
using System.Reflection; 

namespace SMSGatewayTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string auth_id = "XXX";  // obtained from Plivo account dashboard 
      string auth_token = "YYY"; // obtained from Plivo account dashboard 

      RestAPI plivo = new RestAPI(auth_id, auth_token); 

      IRestResponse<MessageResponse> resp = plivo.send_message(new Dictionary<string, string>() 
      { 
       { "src", "37061549145" }, 
       { "dst", "37068824525" }, 
       { "text", "Hi, text from Plivo." }, 
      }); 


      if (resp.Data != null) 
      { 
       PropertyInfo[] proplist = resp.Data.GetType().GetProperties(); 
       foreach (PropertyInfo property in proplist) 
       Console.WriteLine("{0}: {1}", property.Name, property.GetValue(resp.Data, null)); 
      } 
      else 
      { 
       Console.WriteLine(resp.ErrorMessage); 
      } 
     } 
    } 
} 

附:如果我在寫一個問題的時候錯過了一些東西,請詢問它 - 這是我第一次使用短信網關的經驗

+0

RestSharp.IRestResponse'1'只是一個名爲'IRestResponse'的通用類型,它帶有一個通用類型參數。這就是它在IL中的命名方式 - 在C#中的等價物就像'IRestResponse '一樣。 – Luaan

+0

@Luaan,謝謝,這是有道理的,儘管我仍然不明白爲什麼編譯器試圖轉換smth,根據API doc send_message()方法具有相同的類型。 –

+0

其實,類型名稱*是*可疑 - 你確定你正確地複製它?如果是C#或IRestResponse [1] [System.String]',但肯定不是'IRestresponse'1 ',它應該是'IRestResponse '。你確定你遵循了這封信的安裝說明嗎? VS爲'plivo.send_message'方法顯示什麼樣的返回類型? – Luaan

回答

2

因此經過幾個小時的調查後,我設法找出案件。似乎自動NuGet安裝安裝RestSharp版本100.0.0,並且您需要105.1.0.0。解決方法是在NuGet控制檯中輸入以下內容: 安裝包RestSharp -Version 105.0.1

+0

我也有同樣的問題。但是當我嘗試該方法建議它沒有工作,因爲nuget說沒有更新可用。這個問題似乎是Plivo版本2包使用這個依賴。 要修復它,我恢復到使用RestSharp 104.4的Plivo 1.3.7,它的工作原理 –

+0

@TopDev我們在2.0.1中也遇到了這個問題,但在1.3.7上工作正常,你碰巧使用了單聲道嗎? – vonec

+0

我剛剛嘗試了v2.0.0,它工作正常,似乎問題是在nuget包中沒有配置正確的RestSharp依賴項。我在這裏記錄了這個問題:https://github.com/plivo/plivo-dotnet/issues/25 – vonec

相關問題