Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeContracts issue

Hello I have a little issue regarding CodeContracts. I have a class library project which as a class with a method foo(string s1, string s2); inside the foo method, I have a Contract.Requires(s1 != null). So if I understand the meaning of my code (yes, I just installed CodeContracts and playing with :), the contract will check the s1 != null expression during build process and in runtime, throwing ArgumentException>. I wanted to test the behavior, when I call foo(null, "test") from class lib project, the designer tells me about the issue, but when I call it from the winform app project, I don't get any warnings in error list window. So does this mean that code contracts works only in the project they reside and not outside? Thanks

UPDATE


I forgot to mention that the preconditions I have added doesn't work in static analysis. However they do throw ArgumentException with appropriate message in runtime.

like image 824
Davita Avatar asked Feb 25 '23 17:02

Davita


1 Answers

Ok guys, thanks to MS team, I found the problem. The reason of such a strange behavior was that my assembly's name ended with ".Contracts.dll". And the problem is that static analyzer doesn't check assemblies whose names ends with that. I renamed the assembly and everything works like a charm, just like any other MS product :)

like image 64
Davita Avatar answered Mar 04 '23 06:03

Davita