代码合同:ccrewrite 退出并显示代码 -1?

发布于 2024-10-31 19:39:32 字数 494 浏览 1 评论 0原文

我是代码合同的新手。我下载了最新版本的代码合约项目(1.4.40314.1)并开始在我的项目中实现它。当我通过 VS2010 中的“代码合同”选项卡启用“运行检查”时,出现此错误

Error 1 The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@Application1ccrewrite.rsp" 都会以代码 -1 退出。

每次我构建项目时, 请帮忙。


现在这对我来说是一个大问题。 每个使用代码合同的项目都在 VS2010 错误窗口中显示相同的错误,并且在输出窗口中找不到“Application1ccrewrite.rsp”,但它确实存在。


我尝试了一切。我安装了两个版本(Pro、Std),但问题仍然存在。请帮忙!


屏幕截图

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

天涯沦落人 2024-11-07 19:39:32

我也有这个问题。就我而言,问题是 ccrewrite 无法处理网络文件夹中的文件,但要求项目位于本地硬盘上。

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.

挽心 2024-11-07 19:39:32

我遇到了这个问题。导致问题的类库的程序集名称和默认命名空间与目标文件夹中现有的 DLL 具有相同的名称。我一直在重构我的代码,虽然 CS 文件中的命名空间已全部更改为命名空间 2,但属性文件中的默认命名空间仍然是命名空间 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...

音栖息无 2024-11-07 19:39:32

有时,当您的解决方案路径太长时,尤其是对于许多项目,您可能会遇到这种情况。

尝试移动到 c:\temp 并构建它,它可能会修复它(当然,如果您在当前所在的文件夹中需要它,这可能不是一个解决方案)。

我在早期的 CC 版本中注意到了这个错误,现在可能已修复。

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.

初见你 2024-11-07 19:39:32

不知道你是否也遇到了和我一样的问题,但我也看到了这个错误。就我而言,我有一个带有 switch 语句的方法,并且根据所采用的分支,应用了不同的要求:

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.");
    }
}

当我尝试构建时,这给了我您在错误列表中指出的错误。在输出窗口中,我得到了这个:

EXEC:参考汇编生成器
警告:有问题
方法中的合同号 1
'TerraCognita.LoanExpress.Domain.Loan.CreateLoanTransaction'
AsmMeta 失败且未捕获
异常:由于操作无效
到对象的当前状态。

我将每个分支推入其自己的方法中,使 Contract.Requires 每个方法中的第一行代码,并且我不再遇到编译问题。看来 Contract.Requires 必须是方法中的第一行代码 - 这是有道理的,因为它们旨在用于定义前置条件。

希望这有帮助。

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.

婴鹅 2024-11-07 19:39:32

解决方案是将前置条件和后置条件放在第一行。 ccrewrite 不接受前置条件和后置条件位于命令行下方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文