Unhandled exception details in VS 2012 - Where is it?

I don't know if the following is a bug or just some unfortunate side effects or an unchecked checkbox somewhere...

I was trying check out how Xamarin.Android (4.8.00013) is handling exceptions when I am running my code in Android simulator. (VS 2012 version: 11.0.60610.01).

An exception results in an empty "An unhandled exception occurred"
image dialog. There's no chance to open the exception and read the message, or check inner exception. Not the wet dream of a UX designer...

Which is not that bad if the call stack can be checked (simple case: exception thrown from a non-static method from a non-static class), and pressing break shows the line where the exception would be thrown.

Now throw exception in a static method:

  1. the stack does not contain your static method

  2. you are left with a blank pop up ("Something bad has happened" - OK, then I try to do "Unsomething"...)

    A) If you press break you are thrown to an other dialog, saying "You must check disassembly window if you are trying to figure it out"

    checking disassembly window: it's blank...

    B) If you press Continue, it will result in the following dialog:

image

"Loading..." will never finish. It's probably a bug.

What can I do to find out what line has thrown the exception in the static case?

Posts

  • AndrasTothAndrasToth HUMember

    I have found the solution:

    Check Output window => "Show output from: Debug".
    I still consider it a bug as the dialog still did not load this:

    "UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for CoreStuff.Loggers.Log ---> System.InvalidOperationException: ILogger factory was not initialized. Check your composition root!
    08-14 14:56:02.757 I/MonoDroid( 1053): Call stack:
    08-14 14:56:02.757 I/MonoDroid( 1053):    at CoreStuff.Factories.LoggerFactory.Create(System.String categoryName)
    08-14 14:56:02.757 I/MonoDroid( 1053):    at CoreStuff.Loggers.Log..cctor()
    

    etc. etc.
    But at least, I can figure out what the problem...

  • MarkRenwickMarkRenwick GBMember ✭✭

    I am having a similar problem to this, if I hit an error I always get "An unhandled exception occured." but there's nothing in the debug log and the popup gives no details, I can't even get the stack trace to find the issue.

    Can someone help with this?

  • michael_fortinmichael_fortin USMember
    edited July 2014

    Anyone found a real solution to this issue? I'm seeing this behavior in Xamarin 3.1, VS 2013, Xamarin Studio 5.1.4 (latest version of everything right now).

    I have no way to see the stack trace to find the root cause of the issues I'm having, which is infuriating!

    The debug log shows nothing, just like @MarkRenwick. In Xamarin Studio, the app breaks at "System.Diagnostics.Debugger.Mono_UnhandledException_internal ()" and there's no trace of a useful stack trace (pun intended).

    Also note that my throwing code uses async/await. Maybe it has to do with this? After a quick test it seems the VS debugger breaks on the exception-throwing line when the line in question isn't in an async method (albeit with the same completely useless exception dialog). Did you guys have these issues with async code?

    How come no one from Xamarin answered to this post?

    Here is the full stack trace I'm seeing in Xamarin Studio. As you can see, there isn't much else than internal Mono stuff:

    System.Diagnostics.Debugger.Mono_UnhandledException (ex=) in
    object.430500da-07c1-4a4a-b45b-c66f2ddc07d0 (Parameters=) in
    System.Runtime.CompilerServices.AsyncVoidMethodBuilder.AnonymousMethod__0 (Parameters=) in
    Android.App.SyncContext.Post.AnonymousMethod__0 (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
    Java.Lang.Thread.RunnableImplementor.Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
    Java.Lang.IRunnableInvoker.n_Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/163212a9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
    object.430500da-07c1-4a4a-b45b-c66f2ddc07d0 (Parameters=) in

  • DavidOlubajoDavidOlubajo GBMember

    @michael_fortin‌ : this is exactly the same issue that I cant stand... it is killing me that when I have an exception, Xamarin Studio does not break on the affected line; all I'm left with is an unuseful stack trace (exactly like what you have pasted).

    Are the Xamarin Engineers reading these threads ??

  • CheesebaronCheesebaron DKInsider, University mod

    Don't press break, keep pressing continue and it will spit out the stack trace in the output window.

  • @Cheesebaron Like I mentioned in my previous reply, the stack trace that's printed to the output window is all internal mono code, not app code. This means we can't see what exception was thrown and where, only that there was an exception.

    The workaround you mentioned works for "normal" exceptions in non-async code, through.

  • KrishnaPatelKrishnaPatel INMember

    Anybody from Xamarin? As @michael_fortin‌ said, the stack trace is limited to mono internal. For example I am getting exception in Parse component, but the stack trace I get after keep hitting 'Continue' is limited to Mono - there is no way to know what's going wrong in Parse.

  • PaulPCEPaulPCE USMember ✭✭

    I know this is a really old thread but I keep seeing this too. I couldn't find a bug report about it, so I've logged one here

  • JesperVindJensenJesperVindJensen DKMember

    Did anyone find a solution to this problem, or is it still a dead end ?

  • GeirSmestadGeirSmestad USMember

    It appears I have a similar issue; Visual Studio Premium 2013 with latest version of Xamarin. NullReferenceExceptions when debugging on an Android device never break to the line where the exception occurred. A stack trace can usually be found by pressing break and checking the output window, but debugging is complicated by being unable to halt execution and inspect the values of local variables.

    I am unsure if this is intended behavior or a real issue, but the symptoms are very similar to what is described here. It's not a showstopper, but it does complicate debugging quite a bit.

  • HarikrishnanHarikrishnan USMember ✭✭

    Am facing the same issue in Visual Studio 2013. Have anyone found a solution for this?

  • OndrejSkrabanekOndrejSkrabanek CZMember

    You can find the stacktrace in the Android Device Logging window (go to View->Other windows->Android Device Logging...) and filter by "MonoDroid".

  • How log will it take until xamarin actually understands that this is very important and we need it!!!!!!!
    We need to be able to see the callstack when an exception happens and be able to walk the stack to see variables.
    This is standard in visual studio for windows applications.
    Is it that hard or are you plain ignorant?!?!

  • FilipDrsekFilipDrsek USMember ✭✭

    Why is this problem still unresolved? This slows me down too much. How can I deliver my work before the deadline if it keeps crashing on such an exception, I cannot track down its details and origin and therefore I do not know how to solve it?

  • pauldpauld USMember ✭✭

    My solution was to switch back to a Mac for Android development, at least until this is fixed for my code gets stable enough to not throw confusing exceptions (!!). Testing in the Mac showed that my exception was in async code.

  • aleccalecc PLMember

    VS2015 and still the same issue...

  • BobZuradBobZurad USMember ✭✭

    I'm seeing this issue with VS2015 Update 3 and Xamarin 4.2.2

    As @Cheesebaron mentioned earlier, keep hitting continue. Then when Visual Studio stops debugging, you'll see the stack trace in the Output Debug window. You might have to scroll up a little. Search for Unhandled Exception. Here's what I see:

    Unhandled Exception:
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in System.ComponentModel.DataAnnotations.ValidationContext:.ctor (object,System.Collections.Generic.IDictionary`2<object, object>): method body is empty.

    at ..... (stack trace of my own code)

    I can now see that the exception originated from my own source code, so I know what I have to fix.

    Thank you @Cheesebaron for posting! This helped me tremendously!

  • BobZuradBobZurad USMember ✭✭

    Also, in Visual Studio go to Help > Xamarin > Open Logs. A folder will open and the exceptions you're looking for are in those files.

  • vardthomasvardthomas UMMember

    2017 Update 2 and I'm still seeing this issue.

  • EsmaeilEsmaeil USMember
    edited June 2017

    this is really frustrating, this post is 5 years old but the problem still exist,
    I'm using VS 2017 and have them same issue,
    no exception details no stack trace, when we don't know what the problem is how can we fix the problem?

  • dev.kramdev.kram PHMember ✭✭
    edited June 2017

    In VS 2017. I just hit the continue button until the app stops. And on the Output console, you can see stack traces, including information about the app code.

  • PulkitPulkit AUMember ✭✭

    Any fix for the above issue, cannot see any log + I am using the terrible MVVMCross which is making life worse

  • ThomasBowenThomasBowen USMember ✭✭

    @Mud said:
    So I ran into this myself, and was growing increasingly depressed as I read this thread. Years of posts with no resolution!

    But I found something that worked: I opened my Exception Settings and enabled Break When Thrown for pretty much everything.

    Turns out I had an ordinary, trivially-fixed null reference exception being thrown in my C# code. Without "Break When Thrown", that was bubbling up and I'd get an empty, worthless "An unhandled exception occurred." With "Break When Thrown" enabled, the program stopped in the debugger on the line of code that threw the error, I fixed it, and moved on. Huge relief.

    Hopefully this works for the next guy who's googling leads him here.

    I am that guy and it works! Thank you so much.

Sign In or Register to comment.