Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


15
0
Sign in
to vote
Type: Bug
ID: 776183
Opened: 1/9/2013 4:50:24 PM
Access Restriction: Public
1
Workaround(s)
view
3
User(s) can reproduce this bug

Description

There seems to be an incompatibility between Fakes and CodeContracts when using the "Perform Runtime Contract Checking" option.
Details
Sign in to post a comment.
Posted by Microsoft on 6/6/2014 at 9:53 AM
Thank you for using Visual Studio and for reporting this bug. We are happy to let you know that this issue has been fixed in Visual Studio 2013 Update 2. If you already have Visual Studio 2013, you can upgrade to Update 2 for free or you can install a trial version from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 10/11/2013 at 3:05 PM
Thanks for reporting the problem. We have made changes in Visual Studio 2013 Update 1 to ignore properties, methods and events marked with the CompilerGeneratedAttribute when generating Stubs and Shims. The $InvariantMethod$ emitted by CodeContracts is marked with this attribute and will be ignored by the fakes code generator.

Thanks,
Oleg Sych
Posted by Microsoft on 10/11/2013 at 3:04 PM
Thanks for reporting the problem. We have made changes in Visual Studio 2013 Update 1 to ignore properties, methods and events marked with the CompilerGeneratedAttribute when generating Stubs and Shims. The $InvariantMethod$ emitted by CodeContracts is marked with this attribute and will be ignored by the fakes code generator.

Thanks,
Oleg Sych
Posted by flipchart on 7/10/2013 at 11:07 PM
Hi!

This issue has been around for a while and is a real pain when trying to unit test code with Contracts using Fakes. Would it be possible to give a status update so that we know that it is being addressed. The workarounds aren't really viable for the long term, and this issue forces us to use other mocking frameworks in some situations. We really love Fakes and Contracts and want to use them, but this issue is stopping us.

Thanks for the hard work!
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.
File Name Submitted By Submitted On File Size  
Fakes.zip 1/10/2013 18 KB
Fakes.zip 1/10/2013 18 KB