Boris Makogonyuk Boris Makogonyuk - 4 months ago 54
C# Question

Code Contracts on different projects

I have a project with contracts (project A) that generates a library and another one (project B) that implements an interface from that library.

I've tried copying the contract files from project A to project B and the contracts fire at runtime without problems. But when I'm trying to reference project A from project B. The static analyzer is still working, but the runtime checks no longer work.

Am I doing something wrong? Is there something I do not understand about how code contracts work?


Important: this was discussed here - CodeContracts issue

Replicated a similar project structure in a new solution. Everything worked without any problems. I still could not find what is the matter with the production solution.

Out of despair I created a new CompanyName.ContractsDebug library. Some test contract implementations fired the runtime checks when using that library. Then I tried going for the stupid fix, I refactored the namespace of the old contracts project (CompanyName.Contracts) to a new name (CompanyName.Shared.Contracts). And that somehow fixed everything. Very weird bug.

Update I was hasty to say that moving it to Shared.Contracts worked. Moving it to Shared.IContracts did. I don't know what is the deal with the Contracts keyword.