How to make Debug.Assert work?  
Author Message
Lei Jiang





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

I remember it works long before, but it never works now.

I have defined DEBUG symbol, build in Debug configuration, turn on "break when any Exception throw" option, but the Debug.Assert never assert even the condition is false.

I am using Whidbey Beta2. Is there anything wrong in my settings

Thanks!





.NET Development35  
 
 
Vikram





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

Hi,

Are you using C# or Visual Basic I tried using C# and it works. Sample I used is below:

Debug.Assert("st" != "st");

You need to check the "Define DEBUG constant and Define TRACE constant in the Build Properties in VS2005.

Regards,
Vikram



 
 
Lei Jiang





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

Of course I have done this.

The same program does not throw assert exception either on the machine of one of my colleague, but works fine for another colleague! So there must be some configuration difference between these machines. However, we have checked all settings and they are all the same. Maybe we omitted something

Thanks!

 
 
Vikram





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

Hi,

Do a simple test. Build the .Exe on the machine where it is working and then run on ur machine and see if it works Do the other way round, by building on ur machine then running ur colleague's machine.

Then we can know if its a compile time issue or a runtime issue and do further investigation based on that.

Regards,
Vikram

 
 
Lei Jiang





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

I just create a simple WinForm app in VS.NET 2005 Beta2 and add Debug.Assert(false) in the first line of Main method. However, this time it works!

It just does not work in my large project I mentioned before. I doubt I have changed some settings of the project or VS.NET IDE and caused this problem.

 
 
Vikram





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

Hi Lei,

It cant be the IDE settings since it worked for the other project. So it has to be the project settings. Compare the .csproj/.vbproj file that u have with the other file to see if u can locate any specific setting that has been changed in the project file.

Regards,
Vikram

 
 
Lei Jiang





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

I have compared the project settings but there is no difference. If it's caused by project settings, why it works under the same project settings on another machine

Thanks!


 
 
Vikram





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

Hi,

Just to check if the build went OK, add the following statement in the Form_load or someplace where it would get executed and see if the MessageBox comes up. This way you will know if the DEBUG constant is available at runtime or not.

Did you copy the EXE from the machine where it worked and try

#if
DEBUG

MessageBox.Show("DEBUG Defined");

#endif

Regards,
Vikram



 
 
thomas woelfer





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

i see the same behaviour here. only happens in our large project, doesn't repro in normal apps. i opened a case in ladybug. ( http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=df98cdcd-ee58-4ac9-accb-a16de2e2a369 )

WM_FYI
thomas woelfer
http://www.die.de/blog


 
 
Nuno31415





PostPosted: .NET Base Class Library, How to make Debug.Assert work? Top

I think I got the same problem:

- Debug.Assert() does not work in a specific c# class library;
- It works correctly in other class libraries and console applications;
- DEBUG is defined and build/run are done in DEBUG mode;
- The Assert message is printed out in the output, for failed asserts in this class library;

- The Assert is ignored and execution continues normally, for failed asserts in this class library;
- No Asser dialog is presented;
- Consistent behaviour - always happens for this class library;

With the help of the link of the previous post, I found that i could not do: new UIPermission(UIPermissionWindow.SafeSubWindows).Demand()

This happened because my assembly had security permissions that would not allow it, so I commented out the following lines, in the AssemblyInfo.cs file:

//[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
//[assembly: PermissionSet(SecurityAction.RequestOptional, Name = "Nothing")]

Hope this helps anyone!