Bug 39543 - Occasional crash in Xamarin.Utilities.Android.ActivityEx.ShowError
Summary: Occasional crash in Xamarin.Utilities.Android.ActivityEx.ShowError
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-03-11 10:35 UTC by Jakub Holovsky
Modified: 2017-08-23 20:52 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Jakub Holovsky 2016-03-11 10:35:12 UTC
We have been getting this error occasionally through our error logging service but myself I haven't been able to reproduce this by myself.

java.lang.Throwable: Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
at Android.Runtime.JNIEnv.CallBooleanMethod (intptr,intptr,Android.Runtime.JValue*) <0x000c3>
at Android.Widget.ListView.RemoveFooterView (Android.Views.View) <0x0016f>
at Psonar.Apps.Droid.PayPerPlay.SearchResultsActivity.<HideLoading>b__14 () <0x00107>
at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f>
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>
at (wrapper dynamic-method) object.d9d1aeea-6950-43d1-a69b-81adb2128d5b (intptr,intptr) <0x0003b>

  --- End of managed exception stack trace ---
java.lang.ClassCastException: android.widget.ArrayAdapter cannot be cast to android.widget.HeaderViewListAdapter
	at android.widget.ListView.removeFooterView(ListView.java:393)
	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
	at android.app.Activity.runOnUiThread(Activity.java:4662)
	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
	at android.os.Handler.handleCallback(Handler.java:800)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:194)
	at android.app.ActivityThread.main(ActivityThread.java:5476)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:525)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
	at dalvik.system.NativeStart.main(Native Method)

	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
	at android.app.Activity.runOnUiThread(Activity.java:4662)
	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
	at android.os.Handler.handleCallback(Handler.java:800)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:194)
	at android.app.ActivityThread.main(ActivityThread.java:5476)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:525)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
	at dalvik.system.NativeStart.main(Native Method)

There are two related threads:

http://forums.xamarin.com/discussion/comment/184960/#Comment_184960
https://github.com/xamarin/Xamarin.Auth/issues/75

that are pointing out the issue that is sitting in  "ActivityEx" in "Xamarin.Utilities.Android"

in method that is looking like this:

public static void ShowError(this Activity activity, string title, string message)
{
    var b = new AlertDialog.Builder(activity);
    b.SetMessage(message);
    b.SetTitle(title);
    b.SetNeutralButton("OK", (s, e) =>
    {
        ((AlertDialog)s).Cancel();
    });
    var alert = b.Create();
    alert.Show();
}

seems like alert.Show() is causing the issue. Could you please have a look at this issue?
Comment 1 Jakub Holovsky 2016-03-11 10:39:52 UTC
After I browsed the code it seems like the problem is here:

namespace Xamarin.Utilities.Android
{
  internal static class ActivityEx
  {
    public static void ShowError(this Activity activity, string title, Exception exception)
    {
      Exception exception1 = exception;
      while (exception1.InnerException != null)
        exception1 = exception1.InnerException;
      ActivityEx.ShowError(activity, title, exception1.Message);
    }

    public static void ShowError(this Activity activity, string title, string message)
    {
      if (activity.IsFinishing)
        return;
      AlertDialog.Builder builder = new AlertDialog.Builder((Context) activity);
      string message1 = message;
      builder.SetMessage(message1);
      string title1 = title;
      builder.SetTitle(title1);
      string text = "OK";
      builder.SetNeutralButton(text, (EventHandler<DialogClickEventArgs>) ((s, e) => ((Dialog) s).Cancel()));
      builder.Create().Show();
    }
  }
}

on this line:

builder.Create().Show();
Comment 2 Prashant [MSFT] 2017-06-28 04:29:47 UTC
Thank you for taking the time to submit the bug. We are unable to reproduce this issue. Please attach a reproduction to the bug by starting with a clean Xamarin.Android project and adding just the code necessary to demonstrate the issue.
Comment 3 Cody Beyer (MSFT) 2017-08-23 20:52:32 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!