Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM / Xamarin Forms - HttpClient doesn't work #146

Closed
zbigniew-gajewski opened this issue Apr 25, 2018 · 8 comments

Comments

Projects
None yet
5 participants
@zbigniew-gajewski
Copy link

commented Apr 25, 2018

Ooui, Ooui.Wasm, Ooui.Forms 0.10.222.

The code:

namespace OouiTestXamlApp
{
    using Ooui;
    using System.Net.Http;
    using Xamarin.Forms;

    class Program
    {
        static void Main(string[] args)
        {
            Forms.Init();
            var page = new MainPage();
            UI.Publish("/", page.GetOouiElement());
            GetData();
        }

        public static async void GetData()
        {
            var httpClient = new HttpClient();
            var response = await httpClient.GetAsync("http://www.google.com");
        }
    }
}

Browser console shows error:

System.PlatformNotSupportedException: Operation is not supported on this platform.

The whole error message:

GET http://localhost:52222/ [HTTP/1.1 200 OK 3ms]
GET https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css [HTTP/2.0 304 Not Modified 52ms]
GET http://localhost:52222/ooui.js [HTTP/1.1 200 OK 19ms]
GET http://localhost:52222/mono.js [HTTP/1.1 304 Not Modified 1ms]
GET https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css [HTTP/2.0 304 Not Modified 55ms]
mono.js:1:34855
Unhandled Exception:
mono.js:1:34855
System.PlatformNotSupportedException: Operation is not supported on this platform.
mono.js:1:34855
  at System.Net.WebProxy.CreateDefaultProxy () <0x2836738 + 0x00004> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetSystemWebProxy () <0x28365e0 + 0x00000> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetDefaultProxy_UsingOldMonoCode () <0x2836498 + 0x00000> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetSection () <0x28362e0 + 0x00022> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.WebRequest.get_InternalDefaultWebProxy () <0x2835f28 + 0x0002c> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.HttpWebRequest..ctor (System.Uri uri) <0x28185e0 + 0x000d2> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) <0x2817bf8 + 0x00016> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
  at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () <0x2827030 + 0x00076> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at System.Net.Http.HttpClient+<SendAsyncWorker>d__47.MoveNext () <0x27b38e8 + 0x0017e> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at OouiTestXamlApp.Program+<GetData>d__1.MoveNext () <0x275a920 + 0x000e0> in <81d99247780f47eba866b9de0917b7d4>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) <0x2d8c3f8 + 0x00014> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) <0x2d8c270 + 0x00026> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x2d73a28 + 0x000f0> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x2d736c8 + 0x00020> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0x2d8c1f0 + 0x00046> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ThreadPoolWorkQueue.Dispatch () <0x2d6e780 + 0x000f4> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x2d6e370 + 0x00000> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
[ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Operation is not supported on this platform.
mono.js:1:34855
  at System.Net.WebProxy.CreateDefaultProxy () <0x2836738 + 0x00004> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetSystemWebProxy () <0x28365e0 + 0x00000> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetDefaultProxy_UsingOldMonoCode () <0x2836498 + 0x00000> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Configuration.DefaultProxySectionInternal.GetSection () <0x28362e0 + 0x00022> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.WebRequest.get_InternalDefaultWebProxy () <0x2835f28 + 0x0002c> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.HttpWebRequest..ctor (System.Uri uri) <0x28185e0 + 0x000d2> in <c5e34d81ad314f7ab9644fbd9cbc69b1>:0 
mono.js:1:34855
  at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) <0x2817bf8 + 0x00016> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
  at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () <0x2827030 + 0x00076> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at System.Net.Http.HttpClient+<SendAsyncWorker>d__47.MoveNext () <0x27b38e8 + 0x0017e> in <bb3c97b3061e4bd2ab2156520b1e6fdd>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at OouiTestXamlApp.Program+<GetData>d__1.MoveNext () <0x275a920 + 0x000e0> in <81d99247780f47eba866b9de0917b7d4>:0 
mono.js:1:34855
--- End of stack trace from previous location where exception was thrown ---
mono.js:1:34855
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) <0x2d8c3f8 + 0x00014> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) <0x2d8c270 + 0x00026> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x2d73a28 + 0x000f0> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) <0x2d736c8 + 0x00020> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0x2d8c1f0 + 0x00046> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading.ThreadPoolWorkQueue.Dispatch () <0x2d6e780 + 0x000f4> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x2d6e370 + 0x00000> in <b3fce0803fba480fae38154d157eea73>:0 
mono.js:1:34855
ExitStatus: Program terminated with exit(255)
mono.js:1:345822




@praeclarum

This comment has been minimized.

Copy link
Owner

commented Apr 25, 2018

Unfortunately this might be a mono limitation. I will ask them what the best way to do HTTP is.

@praeclarum praeclarum added the question label Apr 25, 2018

@zbigniew-gajewski

This comment has been minimized.

Copy link
Author

commented Apr 26, 2018

Thanks. No worries, I am just testing your library (I am interested in Ooui.Wasm/Forms only) trying to understand the concept in comparison to Silverlight (and have a lot of fun).

Of course 'data access' is necessary, especially HttpClient, which is probably used by another library I am testing - Breeze.Sharp ported to .Net Standard 2.0 ('probably', because I am getting the same error using this library).

BTW, I have found this thread: xaml-Standard - people really miss something similar to Silverlight, which (imho) is your great Ooui.Wasm/Forms lib.

@zbigniew-gajewski

This comment has been minimized.

Copy link
Author

commented Apr 28, 2018

I have noticed that mono has published a new release 5.12.0 Preview (5.12.0.223) where some significant changes have been made which might affect HttpClient issues (Class Libraries section).

Would it be possible to use this version of mono in the next release of ooui (just to check whether it would help to make HttpClient working)?

@D-R-R

This comment has been minimized.

Copy link

commented May 9, 2018

I missed my chance to catch you after the Forms 3.0 talk at Build to make sure I understand this correctly now that the missing Mono forwarders from #96 aren't an issue 😁, but do you think it may be necessary to do what Blazor did and write a custom HttpMessageHandler that calls fetch via interop to get HttpClient working?

https://github.com/aspnet/Blazor/blob/dev/src/Microsoft.AspNetCore.Blazor.Browser/Http/BrowserHttpMessageHandler.cs

https://github.com/aspnet/Blazor/blob/dev/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/Http.ts

@davidlsharp1

This comment has been minimized.

Copy link

commented Jun 7, 2018

@zbigniew-gajewski I think I'm following your same path because I am hitting this error now too. :) This is a fun framework and not the end of the world but HttpClient or something similar would be really nice.

@zbigniew-gajewski

This comment has been minimized.

Copy link
Author

commented Jun 9, 2018

@davidlsharp1 - indeed fun framework, especially for Silverlight addict :) . HttpClient is a must, but as @praeclarum pointed out this is mono/Wasm problem, not Ooui. I am waiting for the next Ooui.Wasm with new mono version included. Another 'nice thing' would be UI controls with mouse support (as important as data access). Fortunately companies like Telerik/Progress is taking it into account: xamarin-forms-on-the-web (user voice page).

@davidlsharp1

This comment has been minimized.

Copy link

commented Jun 9, 2018

That's a great article with props to Frank. Can somebody help me understand the mono problem with HttpClient? Is it specifically a wasm problem?

@seguso

This comment has been minimized.

Copy link

commented Feb 2, 2019

Any updates on this? We are getting PlatformNotSupportedException when doing a simple HttpClient.GetAsync().
It's kind of a showstopper for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.