We all know that Debug.Assert
will not be compiled into the dlls when compiled in release mode. But for some reason Debug.Assert
did appear in the release version of a component I wrote. I suspect that I might have mess up my csproject setting.
Any idea why Debug.Assert
appears in release mode?
P/S: I have double checked to make sure that I was really compiling in release mode before asking this question.
Note 2: I've double checked my csproject, and I found that in the Release config, the Define DEBUG constant is not ticked, indicating that for this part my setting is correct.
Assert works only in DEBUG mode - or, at least, when the DEBUG variable is defined. Otherwise, all those checks will simply get removed from the build result, so they will not impact your application when running in RELEASE mode.
If compiling in release mode includes defining NDEBUG, then yes. The documentations states "The assert routine is available in both the release and debug versions of the C run-time libraries." Looking at the assert.
On the toolbar, choose either Debug or Release from the Solution Configurations list. From the Build menu, select Configuration Manager, then select Debug or Release.
Debug Mode: When we are developing the application. Release Mode: When we are going to production mode or deploying the application to the server. Debug Mode: The debug mode code is not optimized. Release Mode: The release mode code is optimized.
Check the DefineConstants
property in your project file, it should be :
<DefineConstants>DEBUG;TRACE</DefineConstants>
for Debug configuration<DefineConstants>TRACE</DefineConstants>
for Release configurationCheck that you haven't any #define DEBUG
in your code.
I found out the answer; it's because there is a #define DEBUG
preprocessor defined at the start of a cs file inside the project. Removing it solves the problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With