Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin crash when calling external APIs

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)

Best Answer

  • AndrejSobkowskiAndrejSobkowski FRMember ✭✭
    Accepted Answer

    OK, my apologies. The symptoms above were correct and the application did crash without providing any feedback. But the concern seems related to the target page I'm PushingAsync to. Why this happens is still totally unclear but please disregard this question.

Answers

  • AndrejSobkowskiAndrejSobkowski FRMember ✭✭
    Accepted Answer

    OK, my apologies. The symptoms above were correct and the application did crash without providing any feedback. But the concern seems related to the target page I'm PushingAsync to. Why this happens is still totally unclear but please disregard this question.

Sign In or Register to comment.