Why does Contract.Assert throw an assertion dialog even when Runtime Checking is Off?

StackOverflow https://stackoverflow.com/questions/19040786

  •  29-06-2022
  •  | 
  •  

Question

I have a number of Contract.Assert statements in my code. When in Debug Mode, the assertions that fail throw an assertion failed dialog.

There are two things I don't understand about this:

  1. Are Contracts not controlled by the Rewiter? So I thought if that it was unchecked, that no Contracts would be enforced. If this is not the case, what is controlled by the Runtime checking checkbox? What is not?

  2. Why is an Assertion dialog thrown? They seem kind of useless, as in Silverlight, all I get is a IE dialog saying that an assertion has failed. I would prefer an exception.

Greg

Was it helpful?

Solution

The Contract.Assert method is also enabled under DEBUG, that's why you get the failure. Under Release, you should not see it.

If you want something other than the dialog, you need to either enable the rewriter, or register a handler with the ContractFailed event handler.

OTHER TIPS

1 - A Contract is a contract, he must be accomplished although if it´s not necessary why use contract? Maybe you could use null labels values in the contract. 2 - Asserting do exactly this, show for the developer there is something going worn, this is mostly used in development environment, when you put in production remember to build in release to exclude this validation from the IL .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top