为什么具有 SecurityTransparent 属性的程序集会导致通过探查器检测的代码抛出 VerificationException?

发布于 2024-12-01 18:27:37 字数 944 浏览 4 评论 0原文

看来当我使用 OpenCover 检测程序集时,程序集与 SecurityTransparent 属性(似乎是AllowPartiallyTrustedCallers)将抛出VerificationException。我想知道为什么会这样,以及是否有其他解决方案可以在不包含这些属性的情况下重新编译程序集,即条件编译,如下载的 MVC3 代码中所示(但奇怪的是,当我浏览Codeplex 上的存储库)。请注意,如果没有这些程序集属性,覆盖率运行不会出现问题。

OpenCover 使用 CALLI 指令 发送检测数据(序列点标识符)到分析器。看起来调用该指令的行为会导致异常发生;检测部分看起来很好,并且 JIT 编译新的检测方法没有问题。检测行为不会引起问题,因为如果我删除除了使微小方法胖和小分支长之外的所有检测,代码执行不会出现问题。

目前,我正在使用 Mono.Cecil 检查通过“include-in-coverage”过滤器的程序集,并向用户报告问题,同时跳过检测,然后继续,但我想知道是否有什么我可以做的在分析期间执行此操作以避免此问题并避免重新编译。

总结一下两个问题“为什么会发生?”和“我可以在不重新编译的情况下避免它吗?”

注意:PartCover 似乎也存在此问题,它使用不同的方法来记录访问点。

注意:我是 OpenCover(一个开源代码覆盖工具)的开发人员,目前是 PartCover 的维护者。

It seems when I instrument an assembly using OpenCover, assemblies with the SecurityTransparent attribute (and AllowPartiallyTrustedCallers it seems) will throw a VerificationException. I'd like to know why that is and if there is an alternative solution to recompiling the assembly without those attributes included i.e. conditional compilation, as seen in the downloaded code for MVC3 (but strangely I can't find the same when I browse the repository on codeplex). Note without those assembly attributes the coverage runs without issue.

OpenCover uses a CALLI instruction to send instrumentation data (sequence point identifier) to the profiler. It seems the act of calling this instruction causes the exception to occur; the instrumentation part seems fine and the JIT compiles the new instrumented method without issue. The act of instrumentation doesn't cause issues because if I remove all instrumentation other than make Tiny methods Fat and small branches long the code executes without issue.

Currently I am using Mono.Cecil to examine assemblies that pass the "include-in-coverage" filter and report the issue to the user whilst skipping the instrumentation and then continue, but I'd like to know if there is anything I a can do during the profiling to avoid this issue and avoid recompilation.

So to sum up 2 questions "Why does it happen?" and "Can I avoid it without recompilation?"

NOTE: PartCover also seems to exhibit this issue and it uses a different method to record visit points.

NOTE: I am the developer of OpenCover (an open source code coverage tool) and currently the maintainer of PartCover.

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

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