Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug.Assert appears in release mode

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.

like image 979
Graviton Avatar asked Jun 11 '10 09:06

Graviton


People also ask

Does debug assert work in Release mode?

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.

Does assert work 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.

How do I change debug to Release?

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.

What is difference between Release and debug mode?

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.


2 Answers

Check the DefineConstants property in your project file, it should be :

  • <DefineConstants>DEBUG;TRACE</DefineConstants> for Debug configuration
  • <DefineConstants>TRACE</DefineConstants> for Release configuration

Check that you haven't any #define DEBUG in your code.

like image 78
Julien Hoarau Avatar answered Oct 05 '22 08:10

Julien Hoarau


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

like image 30
Graviton Avatar answered Oct 05 '22 06:10

Graviton