C# ';RestSharp.i响应'1<;T0>';在未引用的程序集中定义

C# ';RestSharp.i响应'1<;T0>';在未引用的程序集中定义,c#,.net,restsharp,sms-gateway,plivo,C#,.net,Restsharp,Sms Gateway,Plivo,我正在开发一个应用程序,需要短信网关服务。我们公司使用Plivo服务。我沿着小路走。 当我尝试构建解决方案时,我收到两个错误: 错误1:在未引用的程序集中定义了类型“RestSharp.IRestResponse”1。您必须添加对程序集“RestSharp,Version=105.1.0.0,Culture=neutral,PublicKeyToken=null”的引用。 错误2:无法将类型“RestSharp.IRestResponse”1隐式转换为“RestSharp.IRestRespon

我正在开发一个应用程序,需要短信网关服务。我们公司使用Plivo服务。我沿着小路走。 当我尝试构建解决方案时,我收到两个错误:

错误1:
在未引用的程序集中定义了类型“RestSharp.IRestResponse”1。您必须添加对程序集“RestSharp,Version=105.1.0.0,Culture=neutral,PublicKeyToken=null”的引用。

错误2:
无法将类型“RestSharp.IRestResponse”1隐式转换为“RestSharp.IRestResponse”

我不知道这些错误的原因,因为我通过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);
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用RestSharp;
使用Plivo.API;
运用系统反思;
名称空间SMSGatewayTest
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串auth_id=“XXX”//从Plivo帐户仪表板获取
字符串auth_token=“YYY”;//从Plivo帐户仪表板获取
RestAPI plivo=新的RestAPI(身份验证id、身份验证令牌);
IRestResponse resp=plivo.send_消息(新字典()
{
{“src”,“37061549145”},
{“dst”,“37068824525”},
{“文本”,“嗨,来自Plivo的文本。”},
});
如果(响应数据!=null)
{
PropertyInfo[]proplist=resp.Data.GetType().GetProperties();
foreach(PropertyInfo属性在proplist中)
WriteLine(“{0}:{1}”,property.Name,property.GetValue(resp.Data,null));
}
其他的
{
控制台写入线(相应错误消息);
}
}
}
}

另外,如果我在写问题时漏掉了什么,请自问吧——这是我第一次使用SMS网关,所以经过几个小时的调查,我终于找到了这个案例。似乎自动NuGet安装需要安装RestSharp版本100.0.0,而您需要105.1.0.0。解决方案是在NuGet控制台中输入以下内容:
安装软件包RestSharp-版本105.0.1

RestSharp.IRestResponse``1
只是一个名为
IRestResponse
的泛型类型,只有一个泛型类型参数。这就是它在IL中的命名方式-在C中的等价物类似于
IRestResponse
@Luaan,谢谢,这是有意义的,尽管我仍然无法理解为什么编译器尝试转换smth,而根据API doc send_message()方法具有相同的类型。实际上,类型名称可疑-是否确实正确复制了它?如果是C#,它应该是
IRestResponse
,或者
IRestResponse``1[System.String]
,但绝对不是
IRestResponse'1
。您确定严格按照安装说明操作了吗?VS为
plivo.send_message
方法显示了什么返回类型?@Luaan,下面是错误日志中的屏幕截图:。发送消息返回类型:我也有同样的问题。但是当我尝试这种方法时,我认为它不起作用,因为nuget说没有可用的更新。问题似乎是Plivo版本2包使用了这种依赖关系。为了修复它,我返回到Plivo 1.3.7,它使用RestSharp 104.4和它works@TopDev我们在2.0.1中也遇到了这个问题,但是在1.3.7中工作得很好,您是否碰巧使用了mono?我刚刚尝试了v2.0.0,它工作得很好,似乎问题在于在nuget包中没有正确配置RestSharp依赖项。我已将问题记录在此处: