11

I'm new to code contracts. I downloaded the latest build of code contract project (1.4.40314.1) and started to implement it in my project. When i enabled 'Runtume Checking' through Code Contracts Tab in VS2010, i got this Error

Error 1 The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@Application1ccrewrite.rsp"" exited with code -1.

everytime i build the project. Plz help.


Now it's a major problem for me. Every project using code contracts is showing same error in VS2010 Errors window and 'Application1ccrewrite.rsp' not found in output window, but it is there.


I tried out everything. I installed both versions (Pro, Std) but the problem persist. Plz help !


Screenshot

Code0987
  • 2,598
  • 3
  • 33
  • 51
  • (cross post with http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/bdde6f82-da17-4121-9e7a-053e5a7ac417) – mafu Apr 11 '11 at 15:12
  • @mafutrct that question at msdn was posted by me as i didn't got answer here. Plz help if you can. – Code0987 Apr 11 '11 at 16:53
  • I have the same issue as this. I have actually created an empty console application and that won't build if "Perform Runtime Contract Checking" is checked. – David Neale Jun 08 '11 at 15:26
  • @David-Neale Tell me if you fix it. I can't find any solution since 30 days and Code-contracts developers couldn't help too. – Code0987 Jun 08 '11 at 16:18
  • :( :) No more i can produce this error after formatting my pc. – Code0987 Jan 10 '12 at 14:25

5 Answers5

2

I had this problem as well. In my case the problem was that ccrewrite cannot work with files in a network folder but requires the project to be on your local hard disk.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
1

Sometimes you can get this when your solution path is too long, especially with many projects.

Try moving to c:\temp and building it, it might fix it (although of course, this might not be a solution if you need it in the folder it currently is).

This bug I noticed in earlier CC versions and may now be fixed.

Stephen Drew
  • 1,415
  • 19
  • 31
1

I had this problem. The Assembly name and Default namespace of the class library that causes the problem had the same name as an existing DLL in the destination folder. I had been refactoring my code and whilst the namespaces in the CS files had all be changed to namespace2 the default namespace in the properties file was still namespace1 When I corrected this the files all built successfully...

0

The solution is to put the pre and pos conditions in the first lines. The ccrewrite does not accept that pre and post conditions are below command lines.

0

I don't know if you had the same problem as me, but I also saw this error. In my case, I had a method with a switch statement, and depending on the branch taken, different requirements applied:

static ITransaction CreateTransaction(
    String transType,
    MyType1 parm1,
    /* Other params unimportant to this example */
    String parm5)
{
    switch (transType) {
        case Transaction.Type.SOME_TRANSFER:
            Contract.Requires<ArgumentNullException>(parm1.Account != null, "Account cannot be null.");
            Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm5), "parm5 cannot be null or empty.");

            // Create instance

            return someInst;

        case Transaction.Type.SOME_OTHER_TRANSFER:
            Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm1.Type), "Type cannot be null or empty.");
            Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm1.Number), "Number cannot be null or empty.");

            // Create instance

            return someInst;

        /* Other cases */

        default:
            throw new ApplicationException("Invalid or unknown transaction type provided.");
    }
}

This was giving me the error you noted in the Errors List when I tried to build. In the output window, I was getting this:

EXEC : Reference Assembly Generator warning : Something is wrong with contract number 1 in the method 'TerraCognita.LoanExpress.Domain.Loan.CreateLoanTransaction' AsmMeta failed with uncaught exception: Operation is not valid due to the current state of the object.

I pushed each branch into a method of its own, making Contract.Requires the first lines of code in each method, and I no longer had a compilation problem. It appears that Contract.Requires must be the first lines of code in a method - which makes sense, since they are intended to be used to define pre-conditions.

Hope this helps.

Remi Despres-Smyth
  • 4,173
  • 3
  • 36
  • 46
  • 3
    It's also well documented that the .Requires and .Ensures must be first in the method (after any legacy-requires). – H H May 10 '11 at 19:47
  • I'm not saying it's not documented. (I've no doubt that it must be in the docs I reviewed, and I overlooked it.) I am saying that if you do this, you will see the error the poster noted. – Remi Despres-Smyth May 11 '11 at 01:21
  • But it not the issue. The error comes when you enable 'Runtume Checking, whether you write or don't write the CodeContract codes. – Code0987 May 11 '11 at 16:39
  • @neeraj: But Remi's answer does indicate that you have to post some code samples. Ar all your Req/Ens calls always at the top of the methods? – H H May 12 '11 at 15:51
  • @Henk Holterman Yes u r right. I always keep them on top. But i'm saying it is not the problem. – Code0987 May 13 '11 at 00:49