开发者

Using Code Contracts, why does ccrewrite require access to every runtime dependency?

开发者 https://www.devze.com 2023-03-18 14:05 出处:网络
I\'m trying to use Code Contracts and I\'m running into a problem that is blocking me.With Contract Reference Assembly set to Build, ccrewrite is erroring while trying to access assemblies that are re

I'm trying to use Code Contracts and I'm running into a problem that is blocking me. With Contract Reference Assembly set to Build, ccrewrite is erroring while trying to access assemblies that are referenced indirectly by assemblies that are referenced directly. These indirect assemblies are not needed to buil开发者_Python百科d the solution, so I'm wondering why they're required by Code Contracts? Also, is there a way to work around this problem without having to provide all runtime dependencies as part of the build?


I assume ccrewrite is trying to walk the dependency chain to analyze it for pre/postconditions, etc.. If the assemblies are referenced by assemblies which you in turn reference, then they would be required for your program to run, so ccrewrite is just performing normal analysis before you actually run the program.

That's based on using JML; I've only just started looking at the .NET Code Contracts myself. But I believe both tools operate on roughly the same principles.


The rewriter looks into method bodies of referenced assemblies in order to extract contracts (the C# compiler never does that). As a result, the rewriter often chases more dependencies than C# which is the problem you ran into.

There are two ways to address this.

  1. add extra paths to directories where the desired libraries can be found (in the contract library paths options). This it the preferred method
  2. As a last resort, you can add the option -ignoreMetadataErrors to the runtime contract options. Note that this is dangerous. In the case that the rewriter truly needs some aspect of the referenced code in order to create proper IL, you might end up with incorrect IL. To guard against this, use peverify on the resulting bits.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号