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

Xamarin.Android throws not implemented exception #108

Open
rusty21 opened this issue Oct 9, 2017 · 28 comments
Open

Xamarin.Android throws not implemented exception #108

rusty21 opened this issue Oct 9, 2017 · 28 comments
Labels

Comments

@rusty21
Copy link

rusty21 commented Oct 9, 2017

On Xamarin Android when attempting to open a connection when there is no internet connection causes the app to crash with a System.NotImplementedException. I've put this code in my MainActivity in the OnCreate() method

       var  _websocket = new WebSocket("wss://ws-us2.pusher.com/app/1?protocol=5&client=pusher-dotnet-client&version=0.0.1")
        {
            EnableAutoSendPing = true,
            AutoSendPingInterval = 8
        };
        _websocket.Error += (sender, args) =>
        {
        };
        _websocket.Open();

I'd be happy to provide additional information if necessary.

@kerryjiang
Copy link
Owner

Do you have the stacktrace of this exception?

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NotImplementedException: The method or operation is not implemented.
System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(Exception exception, int bytesTransferred, SocketFlags flags)<6c708cf596db438ebfc6b7e012659eee>:0
System.Net.Sockets.MultipleConnectAsync.AsyncFail(Exception e)<6c708cf596db438ebfc6b7e012659eee>:0
System.Net.Sockets.MultipleConnectAsync.Fail(bool sync, Exception e)<6c708cf596db438ebfc6b7e012659eee>:0
System.Net.Sockets.MultipleConnectAsync.DoDnsCallback(IAsyncResult result, bool sync)<6c708cf596db438ebfc6b7e012659eee>:0
System.Net.Sockets.MultipleConnectAsync.DnsCallback(IAsyncResult result)<6c708cf596db438ebfc6b7e012659eee>:0
System.Runtime.Remoting.Messaging.AsyncResult.Invoke(AsyncResult)(wrapper managed-to-native)
System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()<896ad1d315ca4ba7b117efb8dacaedcf>:0
System.Threading.ThreadPoolWorkQueue.Dispatch()<896ad1d315ca4ba7b117efb8dacaedcf>:0
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()<896ad1d315ca4ba7b117efb8dacaedcf>:0

@kerryjiang
Copy link
Owner

Which target of the library do you use? I though it is .netstandard one because I didn't release assemblies for 0.15 in the Xamarin platform.

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

Looks like it's monoandroid10, or is that not what you were looking for?

@kerryjiang
Copy link
Owner

Are you sue if you use WebSocket4net 0.15?

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

Installing 0.15 seems to want to target netstandard 1.3, which causes the error, downgrading to 0.14.1 seems to target monoandroid23 which does seem to work. Although when downgrading I also had to uninstall SuperSocket.ClientEngine.Core to get it to work.

@kerryjiang
Copy link
Owner

So the version you have problem now is 0.14.1?

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

Installing version 0.14.1 works, but installing version 0.15 does NOT work

@kerryjiang
Copy link
Owner

So the exception was thrown when you used websocket4net 0.14.1?

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

No the exception is thrown on version 0.15

@kerryjiang
Copy link
Owner

That means you use websocket4net 0.15 .nerstandard version in Xamarin. Is my understanding correct?

@rusty21
Copy link
Author

rusty21 commented Oct 9, 2017

That is true

@kerryjiang
Copy link
Owner

Ok, let me see if we have a work around for this issue.

@kerryjiang
Copy link
Owner

kerryjiang commented Oct 18, 2017

I did a fix.

Could you build the websocket4net by your own with the latest source code?

And set the environment before you start the connection like the code below:

Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", "true");

@rusty21
Copy link
Author

rusty21 commented Oct 19, 2017

I downloaded the source today built the WebSocket4Net.Xamarin solution in release mode. I then referenced the MonoDroid version of the dll in a test project. Put this code in the Main Activity

        System.Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", "true");
        var _websocket = new WebSocket("wss://ws-us2.pusher.com/app/1?protocol=5&client=pusher-dotnet-client&version=0.0.1")
        {
            EnableAutoSendPing = true,
            AutoSendPingInterval = 8
        };
        _websocket.Error += (sender, args) =>
        {
        };
        _websocket.Open();

I disabled wifi and mobile data on the device before launching the application. The error still persists. Same stack trace.

@kerryjiang
Copy link
Owner

Could you check the version numver of the dll you use? And Could you send me the stacktrace again? IT might be different with the old one.

@kerryjiang
Copy link
Owner

Can you use the .net standard version?

@berdon
Copy link

berdon commented Dec 13, 2017

We too see this issue - it's most easily repeated when attempting to connect to an invalid host from Android.

I'll try adding the PREFER_DNS_IN_ADVANCE and see what happens.

@berdon
Copy link

berdon commented Dec 13, 2017

PREFER_DNS_IN_ADVANCE had no appreciable effect; this is running off of:

  • WebSocket4Net 0.15.1
  • SuperSocket.ClientEngine.Core 0.9.0

The project is all using .NET Standard so I'm assuming it's using the .NET Standard versions of WebSocket4Net and SuperSocket. The wrapping project that consumes these packages are at .NET Standard 1.6.

Here's the stack trace:

The method or operation is not implemented.
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure (System.Exception exception, System.Int32 bytesTransferred, System.Net.Sockets.SocketFlags flags) [0x00000] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.MultipleConnectAsync.AsyncFail (System.Exception e) [0x0001a] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.MultipleConnectAsync.InternalConnectCallback (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs args) [0x000b7] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x0000e] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.Socket+<>c.<.cctor>b__306_3 (System.IAsyncResult ares) [0x00057] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Net.Sockets.SocketAsyncResult+<>c.<Complete>b__27_0 (System.Object state) [0x0000b] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0

@migueldeicaza
Copy link

There is a patch for Mono that we need to review, but would love a test case:

mono/mono#6431

@chrswgnr
Copy link

chrswgnr commented Apr 3, 2018

i used the websocket4net 14.1 for a .net framework projekt and switched to .net standard now to use it within xamarin.android and xamarin.ios as well. Which just doesn't work with my implementation on android and ios because of the issue.

Any news on this? Or steps to get it work for the moment?
Any help would be appreciated

@psharrma
Copy link

Hi,

This issue results in instant application crash on both android & iOS, I believe anyone using current version 0.15.2 will stumble upon this issue.

Any update or when can we get a fix for this issue?
Also would really appreciate if we can get a workaround this issue.

@kerryjiang kerryjiang added the bug label Apr 11, 2018
@kerryjiang
Copy link
Owner

Ok, let me check this issue again.

@chrswgnr
Copy link

Well i updated visual studio and xamarin for my project recently and somehow i dont get that error anymore

@psharrma
Copy link

@NeroBoron ,

Are you testing on real device (Android/iOS) or emulator? Also I encountered this issue if i try to open a web-socket while device is in airplane mode.

@chrswgnr
Copy link

On real ones, iPhone 8 and Samsung Galaxy A5 2017 to be specific. Can test it with airplane mode in about a week

@berdon
Copy link

berdon commented Apr 11, 2018

Fwiw, we no longer receive this exception after updating mono.

@psharrma
Copy link

This issue is resolved after upgrading mono.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants