OneSignal / onesignal-dotnet-api

Other
13 stars 12 forks source link

[Bug]: RestSharp constructor not found #14

Open rer145 opened 2 years ago

rer145 commented 2 years ago

What happened?

Version 1.0.1 of the OneSignalApi throws an exception when sending a notification because it can't find a constructor in the RestSharp package.

Message: Method not found: 'Void RestSharp.RestRequest..ctor(RestSharp.Method)'.

StackTrace: System.MissingMethodException: Method not found: 'Void RestSharp.RestRequest..ctor(RestSharp.Method)'.\r\n at OneSignalApi.Client.ApiClient.NewRequest(HttpMethod method, String path, RequestOptions options, IReadableConfiguration configuration)\r\n at OneSignalApi.Client.ApiClient.Post[T](String path, RequestOptions options, IReadableConfiguration configuration)\r\n at OneSignalApi.Api.DefaultApi.CreateNotificationWithHttpInfo(Notification notification, Int32 operationIndex)\r\n at OneSignalApi.Api.DefaultApi.CreateNotification(Notification notification, Int32 operationIndex)\r\n

Using RestSharp 108.0.1, I don't see a constructor in their code that matches the pattern of just taking in a Method.

I'm mixing a .NET Framework API with a .NET Standard Class Library, and the required packages are installed in both projects.

Code Snippet (inside the .NET Standard Class Library, called from the .NET Framework API):

var restApiKey = "......";
var Configuration = new OneSignalApi.Client.Configuration();
Configuration.BasePath = "https://onesignal.com/api/v1";
Configuration.AccessToken = restApiKey;
Configuration.ApiKey.Add("default", restApiKey);

var model = new OneSignalApi.Model.Notification(appId: AppId)
 {
    IncludeExternalUserIds = new List<string> { "..." },
    Name = "Test Message",
    ChannelForExternalUserIds = "push"
};

model.Contents = new OneSignalApi.Model.StringMap { En = "message contents" };

var api = new DefaultApi(Configuration);
var result = api.CreateNotification(model);
return !String.IsNullOrWhiteSpace(result.Id);

Steps to reproduce?

1. Create .NET Framework 4.8.1 API
2. Create .NET Standard 2.0 Class Library
3. Install packages: OneSignalApi 1.0.1, RestSharp 108.0.1, Newtonsoft.Json 13.0.1, JsonSubTypes 1.9.0, System.ComponentModel.Annotations 5.0.0 in both projects
4. Call the class library from the api
5. Get error

What did you expect to happen?

I expected the API to send a push notification message.

Relevant log output

No response

Code of Conduct

rer145 commented 2 years ago

Related to #7. I downgraded RestSharp in both projects to 106.13.0 to match the OneSignalApi package and it works.

rmariotti-choicelunch commented 2 years ago

Are there plans to update this library to use the latest RestSharp (108+)?
RestSharp v107 was a large update and I have other code that also uses RestSharp v107+ features.

Much appreciated any roadmap or plans to use the "modern" RestSharp! Thanks, Ryan

webfletch commented 1 year ago

Yes I would also like to know if you will be supporting the latest version of RestSharp, the latest version of Xero nuget package needs RestSharp 108.0.1 or greater but I cannot install it because OneSignal needs RestSharp below version 107.

Jossec101 commented 1 year ago

Bump, still a big issue nowadays.