RestSharp: Got "Error: Operation is not supported on this platform" in a .NET Core 2.0 application

Expected Behavior

I made a POST request that works well with 106.2.2.

Actual Behavior

I received the same “Operation is not supported on this platform.” error as here after updating NuGet references on a .NET Core 2.0 app (while doing a x-www-form-urlencoded POST), which moved me from 106.2.2 to 106.4.2.

Steps to Reproduce the Problem

Specifications

  • Version: 106.4.2
  • Platform: .NET Core 2.0, Visual Studio for Mac, Mac OS 10.13.6
  • Subsystem:

I compiled and copied this app to an AWS Lambda instance as part of a scheduled job I run, and it failed in that environment too, until I changed the version. Thought it worth mentioning.

StackTrace

{System.PlatformNotSupportedException: Operation is not supported on this platform.
    at System.Net.SystemWebProxy.GetProxy(Uri destination)
    at System.Net.ServicePointManager.ProxyAddressIfNecessary(Uri& address, IWebProxy proxy)
    at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy)
    at System.Net.HttpWebRequest.get_ServicePoint()
    at RestSharp.Http.ConfigureWebRequest(String method, Uri url)
    at RestSharp.Http.PostPutInternal(String method)
    at RestSharp.Http.AsPost(String httpMethod)
    at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method)
    at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)}

Here was the request as well, with details removed… probably not useful but there it is…

var authRequest = new RestRequest("authentication/token", Method.POST);

authRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
authRequest.AddHeader("Accept", "application/json");

authRequest.AddParameter("grant_type", "some_pw");
authRequest.AddParameter("client_id", "some_client");
authRequest.AddParameter("client_secret", "some_secret");
authRequest.AddParameter("username", "my_username");
authRequest.AddParameter("password", "my_password");

var client = new RestClient { BaseUrl = new Uri("some_url") };

var accessToken = client.Execute<AuthToken>(authRequest).Data.AccessToken;

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 44 (19 by maintainers)

Most upvoted comments

RestSharp 106.6.10 (which has been released in the meantime) fixes the problem for me. Stating this here for others who are confused after finding this page with google and reading the discussion.

Version 106.6.9 is still the latest version and my team is hitting this issue in our .Net Core 2.2 application. Are there any updates on this? Do we need to downgrade to 106.4.0?

Also can confirm that downgrading to Restharp 106.4.0 is the fix.

Your above example runs fine, adding var proxy = System.Net.WebProxy.GetDefaultProxy(); kills it. But so it should, because that was deprecated.

I also realised 3 things that are different. 1. My stacktrace is different to the original post. 2. I think in Xamarin.WatchOS I am using Mono not dotnet so that above test and source means nothing. The Mono class for WebProxy spits the same exception for a different reasons. 3. I need more sleep.

Not sure where this GetDefaultProxy call is coming from in the source, maybe its in System.Net stuff itself. Either way I’ve worked round my issue for now.

I am using the latest Restsharp release (106.6.9), still experiencing this problem.

Tried circumventing the problem

  • by setting Proxy on my client to null
  • by explicitly setting a proxy on my client

Does not help. Especially the last case, to me, is surprising. Why would Restsharp need to check for a system proxy when one is explicitly set on the client?

On CentOS Linux Not 106.5.x I went back versions until it worked and found the latest to work was 106.4.0

Previously, we had it crashing on HttpWebRequest.GetSystemWebProxy() but it was changed by a PR not long ago. Check the history there. I tested the PR on Windows VM and it worked. Previously, I was using null in for the netstandard20 target framework but I got many complains that in this case if the default proxy is set, RestSharp is not using it.

My suggestion would be to wrap it in try-catch and use null if it throws.

Of course not. I just wrote that I have no issue with proxy on Mac. On Tue, 2 Oct 2018 at 05:42, beeradmoore notifications@github.com wrote:

I just tried to use RestSharp in a Xamarin.WatchOS app and I got the same message. Unsure if it’s just not supported on that platform or if it happens to be the same issue. I looked at the stack trace from the error and I got

at System.Net.WebProxy.CreateDefaultProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/webproxy.cs:508 at System.Net.Configuration.DefaultProxySectionInternal.GetSystemWebProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:318 at System.Net.Configuration.DefaultProxySectionInternal.GetDefaultProxy_UsingOldMonoCode () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:312 at System.Net.Configuration.DefaultProxySectionInternal.GetSection () [0x00015] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:342 at System.Net.WebRequest.get_InternalDefaultWebProxy () [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/WebRequest.cs:1074 at System.Net.WebRequest.get_DefaultWebProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/WebRequest.cs:1114 at RestSharp.RestClient.ConfigureHttp (RestSharp.IRestRequest request) [0x005da] in <1cb3d8314f0f42828703d44ba4ff4fda>:0 at RestSharp.RestClient.Execute (RestSharp.IRestRequest request, System.String httpMethod, System.Func`3[T1,T2,TResult] getResponse) [0x00011] in <1cb3d8314f0f42828703d44ba4ff4fda>:0

In fact, even doing var proxy = System.Net.WebProxy.CreateDefaultProxy(); causes the same exception to be thrown.

Can anyone confirm if this is the same as in their Core2.0 projects?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/restsharp/RestSharp/issues/1179#issuecomment-426138685, or mute the thread https://github.com/notifications/unsubscribe-auth/ACsMVX8TTUQ_Uc0ls39de3gDKW937zBGks5uguDBgaJpZM4W8pFd .

– Med vennligst hilsen / Best regards, Alexey V. Zimarev

I just tried to use RestSharp in a Xamarin.WatchOS app and I got the same message. Unsure if it’s just not supported on that platform or if it happens to be the same issue. I looked at the stack trace from the error and I got

at System.Net.WebProxy.CreateDefaultProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/webproxy.cs:508 at System.Net.Configuration.DefaultProxySectionInternal.GetSystemWebProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:318 at System.Net.Configuration.DefaultProxySectionInternal.GetDefaultProxy_UsingOldMonoCode () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:312 at System.Net.Configuration.DefaultProxySectionInternal.GetSection () [0x00015] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs:342 at System.Net.WebRequest.get_InternalDefaultWebProxy () [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/WebRequest.cs:1074 at System.Net.WebRequest.get_DefaultWebProxy () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/WebRequest.cs:1114 at RestSharp.RestClient.ConfigureHttp (RestSharp.IRestRequest request) [0x005da] in <1cb3d8314f0f42828703d44ba4ff4fda>:0 at RestSharp.RestClient.Execute (RestSharp.IRestRequest request, System.String httpMethod, System.Func`3[T1,T2,TResult] getResponse) [0x00011] in <1cb3d8314f0f42828703d44ba4ff4fda>:0

In fact, even doing var proxy = System.Net.WebProxy.CreateDefaultProxy(); causes the same exception to be thrown.

Can anyone confirm if this is the same as in their Core2.0 projects?

EDIT: Actually, brand new WatchOS app, no RestSharp I get the exact same problem with the above single line of code. Reverting to 160.2.2, 160.1.0 does not fix the issue as I think the problem is in the System.Net itself. I think my issue may be unrelated. Either that or the VS for Mac update today broke something for everyone.