2

I am developing an app which requires SMS gateway service. Our company uses Plivo service. I followed along the sample code. When I tried to build solution I received two errors:

Error 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'

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

I don't get the reasons for these errors since I installed Plivo and RestSharp API's through NuGet and can see the dll's in Solution Explorer. The second error is even more confusing to me because of the strange type 'RestSharp.IRestResponse'1.

If anyone could advise me on this issues I'd be very grateful.

My source code:

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. If I missed something while writing a question, please, ask for it - it's my first experience with SMS-gateway

Moisej Braver
  • 317
  • 3
  • 14
  • `RestSharp.IRestResponse``1` is simply a generic type named `IRestResponse` with a single generic type argument. That's how it's named in IL - the equivalent in C# would be something like `IRestResponse`. – Luaan Aug 03 '15 at 11:15
  • @Luaan, thank you, that makes sense, though I still can't understand why compiler tries to convert smth, when according to API doc send_message() method has the same type. – Moisej Braver Aug 03 '15 at 11:27
  • Actually, the type name *is* suspicious - are you sure you copied it correctly? It should be `IRestResponse` if C#, or `IRestResponse``1[System.String]`, but definitely not `IRestresponse'1`. Are you sure you followed the installation instructions to the letter? What return type does VS show for the `plivo.send_message` method? – Luaan Aug 03 '15 at 11:37
  • @Luaan, here is the screenshot from error log: http://postimg.org/image/co3hpsxr7/. send_message return type: http://postimg.org/image/v1qd9vg5t/ – Moisej Braver Aug 03 '15 at 11:55

1 Answers1

2

So after a few hours of investigating I managed to find out the case. It seems that automatic NuGet installation install RestSharp version 100.0.0, and you need 105.1.0.0. The solution was to enter the following in NuGet console: Install-Package RestSharp -Version 105.0.1

Moisej Braver
  • 317
  • 3
  • 14
  • i am having the same issue too. but when i tried the method suggested it did not work because nuget said no updates were available. The issue seems to be that Plivo version 2 package uses this a dependency. To fix it I reverted back to Plivo 1.3.7 which uses RestSharp 104.4 and it works – Adrian Hedley Aug 06 '15 at 08:14
  • @TopDev we are having this issue too with 2.0.1 but working fine on 1.3.7, do you happen to be using mono? – vonec Nov 19 '15 at 04:13
  • I just tried v2.0.0 and it works fine, seems like the issue is that the RestSharp dependency is not configured correct in the nuget package. I've logged the issue here: https://github.com/plivo/plivo-dotnet/issues/25 – vonec Nov 19 '15 at 04:59