3

I am using a MessageBox to try and do some manual debugging and this is all i have come up with, how am I supposed to make it work?

private void DisplayMessageBoxText()
        {
            MessageBox.Show("Alert Message");
        }
GJJ
  • 494
  • 3
  • 8
  • 18
  • What is the problem you want to debug with those one liners? – PVitt May 20 '11 at 07:22
  • @PVitt@soandos I cannot use visual studio's debugger as it will trigger some unknown error, hence i cant use breakpoints – GJJ May 20 '11 at 07:25
  • Go in Visual Studio in the menu bar to Debug - Exceptions and check all boxes. Then you'll get automatically a break *before* the exception is thrown. But be aware that there could also be a lot of *false breaks* before you hit the concrete problem. – Oliver May 20 '11 at 07:28

5 Answers5

6

You can write to the debug console using writeline:

System.Diagnostics.Debug.WriteLine("Alert message");

or you can wildly throw alert boxes around using:

System.Windows.Browser.HtmlPage.Window.Alert("Alert Message"); 
Anders Lindahl
  • 41,582
  • 9
  • 89
  • 93
  • when i tried the 2nd choice, theres an error saying its a 'property' but is used like a 'type' – GJJ May 20 '11 at 07:42
  • @GJJ: I cannot reproduce that, it compiles and behaves fine in Silverlight 4 for me. – Anders Lindahl May 20 '11 at 07:53
  • hi sorry if my question was phrased poorly before but im actully trying to display debug information in a messagebox – GJJ May 20 '11 at 10:15
3

There are a few other options for obtaining debug information from your application:

Debug.Assert( - some condition - , "A condition failed");

A Debug.Assert will show a message box if the provided condition is not true.

Another useful tool is Tracepoints, these are like breakpoints, but do not break the application, instead they write information to the Debug console.

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • do you have any solution that utilises a message box – GJJ May 20 '11 at 07:44
  • 2
    quote: A Debug.Assert will _show a message box_ if the provided condition is not true. – Marijn May 20 '11 at 07:47
  • hi sorry if my question was phrased poorly before but im actully trying to display debug information in a messagebox – GJJ May 20 '11 at 10:15
3

Ive used http://www.gurock.com/smartinspect/ a lot, its great for logging various changes, can grab all sorts of objects, statuses and the like. the plus side is you can leave it in your code and if you have problems later, just connect in the listener and see whats happening.

throwing message boxes could also interrupt your program, as you are changing focus, depending on where the error occurs in your app, such as if its a focus/key type problem, you can then have more code happening as the unfocus/refocus type messages get processed.

BugFinder
  • 17,474
  • 4
  • 36
  • 51
0

I don't suppose you're after this?

MessageBox.Show("Error details here");

Just on the off chance it's something you weren't aware of...

Melodatron
  • 610
  • 4
  • 10
0

Perhaps the answer you're looking for is more along these lines?..

    private void DebugObject(object obj)
    {
        string printString = "";

        foreach (System.Reflection.PropertyInfo pi in obj.GetType().GetProperties())
        {
            printString += pi.Name + " : " + pi.GetValue(obj, new object[0]) + "\n" ;
        }

        MessageBox.Show(printString);
    }

This function will print out all the members and their values to a Message Box. If you want any extra information follow the link below.

(Credit to Jon Skeet for his response here: C# VS 2005: How to get a class's public member list during the runtime?)

Community
  • 1
  • 1
Melodatron
  • 610
  • 4
  • 10