none
Unable to hide the failed assertion(debug.assert) dialog window. RRS feed

  • Question

  • Hi, I've been trying to find a way  to disable the dialog window that debug.assert shows when it returns false. I want to do this through an addin that I added to visual studio 2008. Here's a code snippet of what im trying to do (in the Exec method of my addin) :

    #if DEBUG
              handled = true;
              DefaultTraceListener defaultTraceListener = Trace.Listeners["Default"] as DefaultTraceListener;
              defaultTraceListener.AssertUiEnabled = false;
              m_isAssertNuked = true;
    #endif
    

    This is unfortunately not working when I'm debuggin my addin project (when the debug starts I'm launching another instance of VisualStudio with a project path in Command line arguments in the Project's properties > Debug tab). I'm under the impression that the DefaultTraceListener I am retrieving is the one of the Addin's project and not the one (like I would need) of the project I'm using to test my AddIn. Anyone got a clue how could I retrieve the right listener ? If I wasn't clear enough please feel free to ask more information on my problem. Thanks, any help will be greatly appreciated.

    Cheers,

    JD

    PS : If I'm posting in the wring section of the forum I'm sorry and please let me know.

     

    Friday, July 16, 2010 9:44 PM

Answers

  • Hi,

      Thanks for your post.

      We could use the App.config configuration file to disable the default window for the Debug.Assert() and add our own listeners for debug/trace output.

       Below is a complete example. I just implemented a custom listener for demonstration. It just output the message to the console. I hope it could be modified to fit your VisuaStudio Addin scenario.   

     

    using System;
    using System.Diagnostics;
    
    namespace DebugAssertWindow
    {
     public class Program
     {
     public static void Main(string[] args)
     {
      method();
     }
    
     public static void method()
     {
      Debug.Assert(false, "bb");
     }
     }
    
     public class myListener : TraceListener
     {
     public override void Write(string message)
     {
      Console.WriteLine("Write: {0}", message);
     }
    
     public override void WriteLine(string message)
     {
      Console.WriteLine("WriteLine: {0}", message);
     }
     }
    }
    
    

     

     

       The corresponding App.config file.

     

     

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <system.diagnostics>
     <trace>
     <listeners>
     <remove name="Default"/>
     <add name="mylistener" type="DebugAssertWindow.myListener, DebugAssertWindow"/>
     </listeners>
     </trace>
     </system.diagnostics>
    </configuration>
    

     

     

        Some extra reference:

        1. TraceListener Class

        2. How to define custom trace listener in app.config

        3. Disable Debug.Assert() window


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Edited by SamAgain Friday, July 23, 2010 7:54 AM refine
    • Marked as answer by SamAgain Friday, July 23, 2010 10:08 AM
    Friday, July 23, 2010 7:52 AM

All replies

  • Hi,

      Thanks for your post.

      We could use the App.config configuration file to disable the default window for the Debug.Assert() and add our own listeners for debug/trace output.

       Below is a complete example. I just implemented a custom listener for demonstration. It just output the message to the console. I hope it could be modified to fit your VisuaStudio Addin scenario.   

     

    using System;
    using System.Diagnostics;
    
    namespace DebugAssertWindow
    {
     public class Program
     {
     public static void Main(string[] args)
     {
      method();
     }
    
     public static void method()
     {
      Debug.Assert(false, "bb");
     }
     }
    
     public class myListener : TraceListener
     {
     public override void Write(string message)
     {
      Console.WriteLine("Write: {0}", message);
     }
    
     public override void WriteLine(string message)
     {
      Console.WriteLine("WriteLine: {0}", message);
     }
     }
    }
    
    

     

     

       The corresponding App.config file.

     

     

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <system.diagnostics>
     <trace>
     <listeners>
     <remove name="Default"/>
     <add name="mylistener" type="DebugAssertWindow.myListener, DebugAssertWindow"/>
     </listeners>
     </trace>
     </system.diagnostics>
    </configuration>
    

     

     

        Some extra reference:

        1. TraceListener Class

        2. How to define custom trace listener in app.config

        3. Disable Debug.Assert() window


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Edited by SamAgain Friday, July 23, 2010 7:54 AM refine
    • Marked as answer by SamAgain Friday, July 23, 2010 10:08 AM
    Friday, July 23, 2010 7:52 AM
  • Thanks Sam... sorry for the delay of my response, your help has been greatly appreciated.
    Friday, August 20, 2010 9:07 PM