&#39; RestSharp.IRestResponse`1 <T0>&#39;在未引用的程序集中定义

时间:2015-08-03 11:13:15

标签: c# .net restsharp sms-gateway plivo

我正在开发一款需要短信网关服务的应用。我们公司使用Plivo服务。我跟着sample code。 当我尝试构建解决方案时,我收到了两个错误:

错误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>'

我没有弄清楚这些错误的原因,因为我通过NuGet安装了Plivo和RestSharp API,并且可以在解决方案资源管理器中看到这些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);
            }
        }
    }
}

P.S。如果我在撰写问题时遗漏了某些内容,请提出要求 - 这是我第一次使用短信网关

1 个答案:

答案 0 :(得分:2)

经过几个小时的调查后,我设法找到了案例。似乎自动NuGet安装安装RestSharp版本100.0.0,你需要105.1.0.0。解决方案是在NuGet控制台中输入以下内容: Install-Package RestSharp -Version 105.0.1