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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .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

|
Posted: .NET Base Class Library, How to make Debug.Assert work? |
Top |
|
|
 |
Nuno31415

|
Posted: .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!
|
|
|
|
 |
|
|