Search

Fakes and CodeContracts ContractInvariantMethod gives CS1056, CS1518, CS1519, CS1001 by Kevin Fletcher

Active

12
0
Sign in
to vote
Type: Bug
ID: 776183
Opened: 1/9/2013 4:50:24 PM
Access Restriction: Public
1
Workaround(s)
2
User(s) can reproduce this bug
There seems to be an incompatibility between Fakes and CodeContracts when using the "Perform Runtime Contract Checking" option.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

Using the example found here: http://msdn.microsoft.com/en-us/library/hh549175.aspx

In the component under test, specify to use CodeContracts with the "Perform Runtime Contract Checking" option.

Now insert code to perform a ObjectInvariant check such as:

[ContractInvariantMethod]
private void ObjectInvariant()
{
     Contract.Invariant(_stockFeed != null);
}

When you then try to "Add Fakes Assembly" the compiler will generate in the region of 120 errors, of the types in the title, above.

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

Failure to add fakes assembly

Expected results

add fakes assembly
File Attachments
File Name Submitted By Submitted On File Size  
Fakes.zip 1/10/2013 18 KB
Fakes.zip 1/10/2013 18 KB
Sign in to post a comment.
Posted by Microsoft on 1/14/2013 at 2:59 AM
Hi Kevin, thanks for your response, we have received your project. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Kevin Fletcher on 1/10/2013 at 1:46 AM
Find attached a (fairly) minimal project to reproduce. Please forgive the whimsy.

The project won't build as attached, but if you remove the comments on the #if directive, to prevent compilation of the Contracts Invariant check, it will.
Posted by Microsoft on 1/9/2013 at 11:23 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting a demo project. Please submit this information to us within 4 business days. We look forward to hearing from you with this information.
Posted by Microsoft on 1/9/2013 at 5:52 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by miher on 2/15/2013 at 1:15 AM
I think we have faced the same problem. The CodeContracts rewriter generates protected virtual invariant methods with invalid names. The options we found to work around this :
- Exclude the problematic type from fakes generation via the .fakes file
- Make the problematic type sealed, and the invarint method private, in this case ccrewrite won't make the invariant method protected so fakes wont see it.