From 6cdab16ab145ce757670b41f903c54e404dc5a3d Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Fri, 27 May 2022 22:39:22 +0800 Subject: [PATCH] Fix System.Security.VerificationException Fix System.Security.VerificationException : Operation could destabilize the runtime. --- src/Ninject/Injection/DynamicMethodInjectorFactory.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Ninject/Injection/DynamicMethodInjectorFactory.cs b/src/Ninject/Injection/DynamicMethodInjectorFactory.cs index 801f9788..d07ee47f 100644 --- a/src/Ninject/Injection/DynamicMethodInjectorFactory.cs +++ b/src/Ninject/Injection/DynamicMethodInjectorFactory.cs @@ -42,7 +42,7 @@ public class DynamicMethodInjectorFactory : NinjectComponent, IInjectorFactory /// The created injector. public ConstructorInjector Create(ConstructorInfo constructor) { - var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) }, true); + var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) }, constructor.Module, true); var il = dynamicMethod.GetILGenerator(); @@ -67,9 +67,9 @@ public ConstructorInjector Create(ConstructorInfo constructor) public PropertyInjector Create(PropertyInfo property) { #if NO_SKIP_VISIBILITY - var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }); + var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object), property.Module }); #else - var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }, true); + var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }, property.Module, true); #endif var il = dynamicMethod.GetILGenerator(); @@ -96,9 +96,9 @@ public PropertyInjector Create(PropertyInfo property) public MethodInjector Create(MethodInfo method) { #if NO_SKIP_VISIBILITY - var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }); + var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, method.Module); #else - var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, true); + var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, method.Module, true); #endif var il = dynamicMethod.GetILGenerator();