I've been trying for long now to hook ICorJitCompiler:compileMethod from Managed Code in v4.0 using EasyHook LocalHook.Create. I've obtained the function pointer from unmarshalling an structure like this:
public static class NativeJitInterop
{
    [DllImport("clrjit.dll", CharSet=CharSet.None, SetLastError = true)]
    private static extern IntPtr getJit();
public static ClrJitCompilerHook GetManagedJitCompiler()
{
    ClrJitCompilerHook clrJitCompiler = null;
    IntPtr _clrJitPtr = getJit();
    ICorJitCompiler _corJitCompiler = (ICorJitCompiler)  Marshal.PtrToStructure(_clrJitPtr, typeof(ICorJitCompiler));
    clrJitCompiler = new ClrJitCompilerHook(_clrJitPtr, _corJitCompiler.compileMethod);
    return clrJitCompiler;
}    
[StructLayout(LayoutKind.Sequential)]
internal struct ICorJitCompiler
{
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public CompileMethodSig compileMethod;
}
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal delegate Int32 CompileMethodSig(IntPtr thisPtr, IntPtr corJitInfo, IntPtr methodInfo, UInt32 flags, [Out] IntPtr ILCode, [Out] UInt64 ILCodeSize);
Everything works fine, the structure seems to be unmarshalled without problems and the contained delegate's _methodPtr and _methodPtrAux fields are fill with some pointer values.
The problem arises when I try to set the hook like this:
public void HookClrJitCompiler()
{
    IntPtr _compileMethodPtr = Marshal.GetFunctionPointerForDelegate(_compileMethodDelegate);
    _localJitHook = LocalHook.Create(_compileMethodPtr, new CompileMethodSig(ClrJitCompilerCalled), this);
    _localJitHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
I obtain and AccessViolationException.
I worked this around and set  _compileMethodPtr variable to delegate's _methodPtr. I got no exceptions when cretaing the hook but the hook didn't work either.
what i'm doing wrong?