Bug 11884 - MonoTouch.Foundation.MonoTouchException.Message appears to hide System.Exception.Message
Summary: MonoTouch.Foundation.MonoTouchException.Message appears to hide System.Except...
Status: RESOLVED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger ()
Version: 1.1.x
Hardware: PC Windows
: High major
Target Milestone: 1.2.x
Assignee: Vinicius Jarina
URL:
Depends on:
Blocks:
 
Reported: 2013-04-22 10:56 UTC by Jay French
Modified: 2016-05-10 17:05 UTC (History)
11 users (show)

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


Attachments
screenshot (55.84 KB, image/png)
2013-04-22 16:22 UTC, Sebastien Pouliot
Details
screenshot #2 (20.76 KB, image/png)
2013-04-22 16:23 UTC, Sebastien Pouliot
Details


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 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 FIXED

Description Jay French 2013-04-22 10:56:20 UTC
I'm getting a MonoTouch.Foundation.MonoTouchException when my app loads.  Here's the code:
            // make the window visible
            try
            {
                _window.MakeKeyAndVisible();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }

The debugger hit a breakpoint at Console.WriteLine.  In the Immediate Window, I've typed in the following expressions and gotten the corresponding responses (***** was my replacement to help readability):

ex.Message => "Exception of type 'MonoTouch.Foundation.MonoTouchException' was thrown."

((MonoTouch.Foundation.MonoTouchException)ex).Message => "Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/*****/Library/Application Support/iPhone Simulator/6.1/Applications/*****/*****.app> (loaded)' with name '*****'"

It appears that in the source for MonoTouch.Foundation.MonoTouchException the Message property is declared with "new" or at least without override, so that the Message property on System.Exception is being hidden, and when you call Message on a variable of type System.Exception, even if the data being stored there is a MonoTouch.Foundation.MonoTouchException, the base class's implementation is being returned.
Comment 1 Sebastien Pouliot 2013-04-22 14:33:17 UTC
I'll try to duplicate the issue but the Message property looks fine:

...
       public class MonoTouchException : Exception {
...
		public override string Message {
			get {
				return string.Format ("Objective-C exception thrown.  Name: {0} Reason: {1}", Name, Reason);
			}
...
Comment 2 Jay French 2013-04-22 14:51:37 UTC
I was getting the exception because my main screen's xib file had its Build Action set to None in Visual Studio (instead of InterfaceDefinition), so I'd try that if you want to reproduce the exception I was seeing (Visual Studio broke at that line and all it said was "Exception of type 'MonoTouch.Foundation.MonoTouchException' was thrown."  That wasn't very helpful to me. :)
Comment 3 Sebastien Pouliot 2013-04-22 16:22:26 UTC
Created attachment 3843 [details]
screenshot

I did the same, inside Xamarin Studio, and what I see looks fine (without a catch)
Comment 4 Sebastien Pouliot 2013-04-22 16:23:50 UTC
Created attachment 3844 [details]
screenshot #2

and it also looks good with a catch.

Watch window is ok (as expected). Immediate window too, e.g.

? e
{MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/sebastienpouliot/Library/Application Support/iPhone Simulator/5.0/Applications/AFFA714F-5BF2-4D19-9A1B-7AEE5AA96D2C/WayUp.app> (loaded)' with name 'MainWindow'
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:43 
  at WayUp.Application.Main (System.String[] args) [0x00000] in /Users/sebastienpouliot/git/xamarin/monotouch-samples/WayUpSample/Main.cs:14 }
Comment 5 Jay French 2013-04-22 16:39:36 UTC
Actually, when I put just "ex" in the watch window, I saw the nice ("Objective-C exception thrown...") message, too.  It was only when I put in ex.Message specifically that I saw the generic default message that looked like it was coming from System.Exception.  If you're not seeing any of that maybe it's either a Visual Studio quirk or maybe it was changed in your code and hasn't made it to the stable version yet.
Comment 6 Sebastien Pouliot 2013-04-22 16:42:56 UTC
Asking for the Message property works fine too.

> ? e.Message
"Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/sebastienpouliot/Library/Application Support/iPhone Simulator/5.0/Applications/AFFA714F-5BF2-4D19-9A1B-7AEE5AA96D2C/WayUp.app> (loaded)' with name 'MainWindow'"


That might be an issue only on Visual Studio... moving bug to "iOS for VS", Debugger
Comment 7 Dominique Louis 2013-06-04 10:52:57 UTC
Please retest with latest master.
Comment 8 Saurabh 2013-06-24 13:58:20 UTC
Dominique: We are trying to verify this issue for the 1.2 mtvs release. Is there a concise test case that demonstrates this issue?