Please note that this may be a duplicate of this question , I'm not quite sure.
My problem is that I have a class library project that has a link to a third-party library (COM) library. I want to put contracts in methods in a class library, for example:
public class foo { public static int divide(TypeFromTypeLib tftl, int a, int b) { Contract.Requires<ArgumentException>(b != 0); return a / b; } }
And then use a client project like
var n = foo.divide(null, 4, 2);
But I would also like the client project to also use contracts in some of its methods. Thus, I set the Code Contracts properties for both projects to “Run Runtime Execution Checks” (without which you get a runtime assert statement indicating that it needs this setting).
Now, when I try to compile the client, I get the following error:
Could not find item reference: my_class_lib.foo::divide.
ccrewrite: error: overwrite due to metadata errors.
What seems inevitable - at any time when a method is called that has a type from a library of a third-party type, this happens. Remove this type from the method signature and that will be fine.
Can anyone explain why this is happening? Is this the key to the fact that the structure of my code is fundamentally wrong (if so, why?), Or is it a fad of code contracts? Is there a recommended fix for this problem?
Walderfrey
source share