Why do assemblies with the SecurityTransparent attribute cause instrumented code via a profiler to throw a VerificationException?

StackOverflow https://stackoverflow.com/questions/7218280

سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top