Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Debug Assert failure when building project

Posted on 2009-07-06
19
Medium Priority
?
634 Views
Last Modified: 2013-11-26
Folks - totally baffled here.  I have some Debug.Assert statements in private get Property accessors (before throwing an exception - used when getting and the property hasn't been set yet).  pretty standard stuff.

when I build (Release config), all of these Asserts get hit and I get the pop-up assert message.
This happens both in VS and MsBuild

how is it possible that:
1. Debug.Assert asserts when building?!?!
2. Debug.Assert would assert in a private get?

its as if the build is trying to access the private get?  does it have anything to do with the class, which inherits from System.Workflow.ComponentModel.Activity?
0
Comment
Question by:sfun28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 7
19 Comments
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790456
I have solution for you

Explain:
It is not common to include asserts in release.

Solution:
Note that calls to the Debug.Assert method disappear when you create a Release version of your code. That means that the call that checks the balance will disappear in the Release version. To solve this problem, you should replace Debug.Assert with Trace.Assert, which does not disappear in the Release version
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790475
Asserting and Tracing are two different things.  I think you are misunderstanding the problem.  Debug.Assert is only active in Debug builds.  I'm doing a release build and hitting the assert.  Anyways, asserts shouldn't trigger when building, they should trigger when your code gets run.
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790500
do you use your custom debug asserts right ? and you are trying to build release with these debug asserts right ?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790511
Problem is that Debug classes arent included (linked) in release. So building release with debug asserts in your code can cause many issues.
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790519
I'm trying to figure out why the Assert is fired when I build.  Asserts should fire when you run code, not when you build code.  These are normal Debug.Assert() statements.   I am building release build, but that shouldn't matter.  the compiler will just ignore.  I have Debug.Assert in release builds all over my code and it works just fine.  In this particular case, BUILDING is causing the assert to fire, which is something I've never seen before.  I think it has to do with Windows Workflow.
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790532
As i mentioned in last comment. Compiler (for .NET) cant build release becouse it cant find Debug classes (becouse release dont include them). So it is why thare are issues during building. I have met with similar problem in my projects, I am sure with it.
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790545
when you use Debug.Assert(...) in code, compiler is (during building) trying to find Debug class in include path. But compiler cant find it, so it is asserted during building.
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790556
If you need to use the Debug methods in a C# or Visual Basic Release build, you must define the DEBUG symbol in your Release configuration so Debug class should include during building
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790562
so how do I fix this?  I have other projects with Debug.Assert and it works just fine in release builds.  How do I include the right resources in the path to make this problem go away?
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790568
please read my last comments (i added several)
as i mentioned
try define DEBUG (somewhere at beginning of your source code):
#define DEBUG

Open in new window

0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790569
or as I mentioned replace Debug.Assert with Trace.Assert

and it will work for 99%
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790570
sorry...but i'm still confused.  I don't need Debug methods in release build...i just need them in debug build.  But I don't want to remove them from my code otherwise they will not appear in debug build.  how do you propose that I use Debug.Assert?
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790601
Visual studio has a property called "Define DEBUG constant"  I tried that but it didn't work.  I don't think this is the right solution to the problem.  #define DEBUG is for compiler directives.
According to the MS website:
By default, the Debug.Assert method works only in debug builds. Use the Trace.Assert method if you want to do assertions in release builds.

If this is true, then why are my assertions being fired in Debug build?

0
 
LVL 3

Accepted Solution

by:
Michal-Drozd earned 1500 total points
ID: 24790614
ohh, sorry use following and your problem should be solved:

// in VB.NET
#Const DEBUG = False
 
// in C#
#undef DEBUG

Open in new window

0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790631
True is, debug asserts should be ignored when you use release, and should be working only in debug mode. You just can play with DEBUG constant (in last comment)
If DEBUG is not set (or false), debug asserts should be ignored in all mods (debug and release).
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790643
that worked!  but what did it actually do?  why do I have to undefine DEBUG?  Will Debug.Assert work in debug builds?
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790668
There is somewhere problem, some code or setting in VS.NET which set DEBUG to true during release. As i mentioned in last comment DEBUG constant is what is deciding to include debug asserts or not. And in release it should be undefined(set to false) in background automatically by .NET Framework.
0
 
LVL 1

Author Comment

by:sfun28
ID: 24790703
So I should really find out what the problem is.   Hmm...because if I keep #undef DEBUG then Assert won't work in Debug build, correct?
0
 
LVL 3

Expert Comment

by:Michal-Drozd
ID: 24790782
yes

if you want asserts you must remove #undef DEBUG line
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question