As referenced in the MSDN article CA2140: Transparent code must not reference security critical items:
How to Fix Violations
To fix a violation of this rule, do one of the following:
Mark the code element that uses the security critical code with the
SecurityCriticalAttribute
attribute- or -
Remove the
SecurityCriticalAttribute
attribute from the code elements that are marked as security critical and instead mark them with theSecuritySafeCriticalAttribute
orSecurityTransparentAttribute
attribute.
You have to mark the method that does the pre-JITing with the [SecuritySafeCriticalAttribute]
. Here it is in action:
using System;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Security;
[assembly: AllowPartiallyTrustedCallers]
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
PreJIT();
}
[SecuritySafeCritical]
static void PreJIT()
{
RuntimeHelpers.PrepareMethod(
System.Reflection.Emit.DynamicMethod.GetCurrentMethod()
.MethodHandle);
}
}
}