Code Contract : ccrewrite exited with code -1?

微笑、不失礼 提交于 2019-11-30 18:08:42

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.

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...

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!