Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin crash when calling external APIs

$
0
0

Here is my case (that I thought was simple and common).

MainPage.xaml.cs
private void Button_clicked(...) {
// Rely on backgound thread
MessagingCenter.Subscribe<SerialLoader, SerialRec>(this, "SerialLoader", OnSerialLoaded);
// Trigger the load
serialLoader.Load(targetID);
}

private void OnSerialLoaded(...) {
Device.BeginInvokeOnMainThread(() => Navigation.PushAsync(...));
}

SerialLoader.cs
public void Load(string targetID,) {
// API service call that "forces" me to use the following
client.LoadCompleted += OnSerialLoadCompleted(sender, e);
client.LoadAsync(...) // I don't think this call is "really async" as return type is void.
}

public void OnSerialLoadCompleted(object sender, LoadCompletedEventArgs e) {
if (...) { // If loaded successfully...
// Notify the receiver that load has completed.
MessagingCenter.Send<SerialLoader, SerialRec>(this, "SerialLoader", e.Result);
}
}

OnSerialLoaded is called successfully then Xamarin crashes the application with the following errors.

EMULATOR
Closes the application without any warning nor message!

SMARTPHONE (API 21)
03-29 18:47:52.617 E/mono-rt (13649): No native Android stacktrace (see debuggerd output).
03-29 18:47:52.617 E/mono-rt (13649):
03-29 18:47:52.617 E/mono-rt (13649):
03-29 18:47:52.617 E/mono-rt (13649): =================================================================
03-29 18:47:52.617 E/mono-rt (13649): Got a SIGSEGV while executing native code. This usually indicates
03-29 18:47:52.617 E/mono-rt (13649): a fatal error in the mono runtime or one of the native libraries
03-29 18:47:52.617 E/mono-rt (13649): used by your application.
03-29 18:47:52.617 E/mono-rt (13649): =================================================================
03-29 18:47:52.617 E/mono-rt (13649):
03-29 18:47:52.617 F/libc (13649): Fatal signal 11 (SIGSEGV), code 2, fault addr 0xbe562fd0 in tid 13649 (com.s4gv.mobile)

I assume this is related to executions on multiple threads; I had tried without MessagingCenter (see my question "Xamarin crashes when mixing Action and API calls (threading concern?)").

Also, I'm surprised both the emulator and the smartphone crash so badly!

Any help is appreciated as I'm now completely stuck :(

Additional details: VS2017 Community 15.6.4 on Windows 10 Xamarin Forms 2.5.0.280555 Target Android SDK 8.1 (API 27 - Oreo)


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>