我正在尝试在一个大型桌面应用程序项目中使用带有 .NET 3.5 的代码合同,该项目还具有混合模式 C++ DLL 依赖项,以旧的托管 C++ 语法编写。
真正的解决方案至少包含 20 个项目,但假设只有 A、B、C 和 D 项目,以及混合模式 M 项目。C依赖于A、B和M。A、B和C都配置为执行运行时检查,代码重写效果很好。现在我想将一些合同添加到一个更高级别的程序集中,称为 D。D 也依赖于所有其他程序,A、B、C 和 M。现在 D 的代码重写失败并显示以下消息(我已更改名称):
15> Reading assembly 'C' from 'build\debug\C.dll' resulted in errors.
15> ccrewrite : error : Rewrite aborted due to metadata errors. Check output window
15> Input string was not in a correct format.
15> Malformed signature.
15> Index was outside the bounds of the array.
15> Malformed signature.
15> Could not resolve type reference: [M]Name.Space.Class1.
15> Could not resolve type reference: [M].EnumType.
15> Malformed signature.
15> Malformed signature.
15> Could not resolve type reference: [M]Name.Space.Class1.
15> Could not resolve type reference: [M].EnumType.
15> Malformed signature.
15> Malformed signature.
15> Input string was not in a correct format.
15> Malformed signature.
15> Could not resolve type reference: [M]Name.Space.Class1.
15> Could not resolve type reference: [M].EnumType.
15> Malformed signature.
15> Malformed signature.
15> Index was outside the bounds of the array.
15> Malformed signature.
因为关于 M 的消息,我认为问题出在混合模式 C++ DLL 上。但是 C 程序集本身可以成功地重写代码,同时它也引用了 M。
我还认为问题不直接在于 D 程序集,因为我已经在同一解决方案中尝试了其他更高级别的程序集,并且如果它们引用 C,它们就不能被代码协定工具重写。
我使用的版本是 1.2.21023.14
我也在 CodeContracts MSDN 论坛上问过这个问题,但还没有收到任何答案,所以我想我会在这里尝试。我对与此相关的任何解决方法或想法感兴趣。