c# - Code contracts causing error due to potential side-effect -


i new code contracts may have done stupid here :)

i getting error

detected expression statement evaluated potential side-effect in contracts of method '##'. (did mean put expression requires, ensures, or invariant call?)

i have following contracts

contract.requires<argumentnullexception>(obj != null); contract.requires<argumentnullexception>(obj.id != null); 

it failing on second contract obj.id != null (id guid)

now possible id null isn't allowed in method. code contracts raises above compile error. method self doesn't return needs no ensures either.

i have removed contract can compile , placed standard if check. causing this?

you need mark id property [pure]

that tell code contracts analyser has no side-effects.

code contracts don't calling methods have side-effects; code behave differently depending on whether had code contract checking enabled or not, bad thing.

example:

public guid id {     [pure]         {         return _id;     } } 

one further point: how can possible id null if it's guid? guid struct, therefore can't null. possibly nullable guid (i.e. guid?) ?


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -