我正在開發一個需要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);
}
}
}
}
附:如果我在寫一個問題的時候錯過了一些東西,請詢問它 - 這是我第一次使用短信網關的經驗
RestSharp.IRestResponse'1'只是一個名爲'IRestResponse'的通用類型,它帶有一個通用類型參數。這就是它在IL中的命名方式 - 在C#中的等價物就像'IRestResponse'一樣。 –
Luaan
@Luaan,謝謝,這是有道理的,儘管我仍然不明白爲什麼編譯器試圖轉換smth,根據API doc send_message()方法具有相同的類型。 –
其實,類型名稱*是*可疑 - 你確定你正確地複製它?如果是C#或IRestResponse [1] [System.String]',但肯定不是'IRestresponse'1',它應該是'IRestResponse '。你確定你遵循了這封信的安裝說明嗎? VS爲'plivo.send_message'方法顯示什麼樣的返回類型? –
Luaan