microsoft / CodeContracts

Source code for the CodeContracts tools for .NET
Other
883 stars 151 forks source link

Errors at compile when Perform Runtime Contract Checking enabled #330

Open CreepyGnome opened 8 years ago

CreepyGnome commented 8 years ago

When I have "Perform Runtime Contract Checking" enabled to anything other than "None" I get the below errors:

Severity Code Description Suppression State
Error CA0001 CA0001 : Member 'GetConstructor' could not be found in type 'System.Type' in assembly 'Fay.Core, Version=1.0.0.0, Culture=neutral'. Active
Error CA0001 CA0001 : An error was encountered while parsing IL for method: 'System.Diagnostics.Contracts.__ContractsRuntime.Requires(System.Boolean,System.String,System.String)', instruction at offset '0x58' with opcode 'Call'. Active

image

I played with other settings and seems to only be caused by that checkbox being enabled and set to anything other than none.

My Environment

Also I have nothing fancy on the Contracts in the project getting these errors. Nothing more complex than the following examples:

Contract.Requires<ArgumentNullException>(value != null);
Contract.Ensures(Contract.Result<string>() != null);
SergeyTeplyakov commented 8 years ago

Hm... Interesting. Could you share full solution? I'll try to reproduce the issue.

CreepyGnome commented 8 years ago

Once I have it complete it will be open sourced on github however these issues are making it difficult to get it to s state for public viewing.

Until then, @SergeyTeplyakov how would you like me to share it with the Code Contracts team so it remains private at this time, as I don't want to make available publicly yet?

I was hoping to publish it by today, but unfortunately I have been losing time to several code contract related issues this just being the latest that wasn't already reported.

msaville8 commented 8 years ago

I am experiencing the same problem and I am using a similar environment. I discovered that this error goes away when I do either one of the following:

or

KAW24 commented 8 years ago

I can also reproduce this using the following setup:

As others have noted the problem goes away if I disable runtime contract checking or code analysis. I also see the following error if I enable the static checker but disable code analysis

The "Microsoft.Research.CodeContractsAnalysis" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft\Contracts\Bin\MsBuildCodeContracts.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

I can provide a project if necessary although I suspect this is more of a configuration issue because this same machine has previously built other projects successfully. I think the key difference was they were targeting the desktop version of the .NET Framework; they were not portable libraries.