Forum Xamarin.Android

Xamarin crashes when mixing Action and API calls (threading concern?)

AndrejSobkowskiAndrejSobkowski FRMember ✭✭
edited March 2018 in Xamarin.Android

I'm having issues - with an "Assertion crash" - mixing Action and API calls in Xamarin.

MainPage.xaml.cs
private void Button_clicked(...) {
serialLoader.Load(targetID, OnLoadSuccessful):
}

private void OnLoadSuccessful(TargetResult result) {
// Do something
}

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

public void OnSerialLoadCompleted(object sender, LoadCompletedEventArgs e, string targetID, Action OnLoadSuccessful) {
if (...) { // If loaded successfully...
.. call the Action passing the result so that I can handle it in the MainPage.xaml.cs
OnLoadSuccessful(e.Result);
}
}

This crashes the application with the following errors

EMULATOR
03-28 19:12:01.169 W/ (22852): Thread 0xcddbacd0 may have been prematurely finalized
03-28 19:12:01.169 W/ (22852): Thread 0xcddbacd0 may have been prematurely finalized
03-28 19:12:01.169 F/ (22852): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-6/xamarin-android/external/mono/mono/utils/mono-threads.c:563, condition `info' not met

SMARTPHONE (API 21)
03-28 21:29:27.467 E/mono-rt (28909): =================================================================
03-28 21:29:27.467 E/mono-rt (28909): Got a SIGSEGV while executing native code. This usually indicates
03-28 21:29:27.467 E/mono-rt (28909): a fatal error in the mono runtime or one of the native libraries
03-28 21:29:27.467 E/mono-rt (28909): used by your application.
03-28 21:29:27.467 E/mono-rt (28909): =================================================================
03-28 21:29:27.467 E/mono-rt (28909):
03-28 21:29:27.467 F/libc (28909): Fatal signal 11 (SIGSEGV), code 2, fault addr 0x9b691fd8 in tid 29095 (Threadpool work)

I assume this is related to executions on multiple threads; I've tried adding "Device.BeginInvokeOnMainThread" (didn't work) and tried to replace my Action by Func but with no luck. Also, I'm surprised both the emulator and the smartphone crash so badly!

Any help is appreciated.

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.