Exemple #1
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            object[]         arguments       = this.InvokeArgumentsCheck(obj, invokeAttr, binder, parameters, culture);
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                StackCrawlMark  stackCrawlMark    = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackCrawlMark);
                if (executingAssembly != null && !executingAssembly.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", new object[]
                    {
                        base.FullName
                    }));
                }
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            return(this.UnsafeInvokeInternal(obj, parameters, arguments));
        }
Exemple #2
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            object[] arguments = InvokeArgumentsCheck(obj, invokeAttr, binder, parameters, culture);

            #region Security Check
            INVOCATION_FLAGS invocationFlags = InvocationFlags;

#if FEATURE_APPX
            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
            {
                StackCrawlMark  stackMark = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly caller    = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if (caller != null && !caller.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName));
                }
            }
#endif

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != 0)
            {
#if !FEATURE_CORECLR
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }

                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
#endif // !FEATURE_CORECLR
                RuntimeMethodHandle.PerformSecurityCheck(obj, this, m_declaringType, (uint)m_invocationFlags);
            }
            #endregion

            return(UnsafeInvokeInternal(obj, parameters, arguments));
        }
        public override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS  invocationFlags = this.InvocationFlags;
            RuntimeTypeHandle typeHandle      = this.m_declaringType.TypeHandle;

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                StackCrawlMark  stackCrawlMark    = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackCrawlMark);
                if (executingAssembly != null && !executingAssembly.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", new object[]
                    {
                        base.FullName
                    }));
                }
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(null, this, this.m_declaringType, (uint)(this.m_invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE));
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                }
            }
            Signature signature = this.Signature;
            int       num       = signature.Arguments.Length;
            int       num2      = (parameters != null) ? parameters.Length : 0;

            if (num != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 > 0)
            {
                object[] array  = base.CheckArguments(parameters, binder, invokeAttr, culture, signature);
                object   result = RuntimeMethodHandle.InvokeMethod(null, array, signature, true);
                for (int i = 0; i < array.Length; i++)
                {
                    parameters[i] = array[i];
                }
                return(result);
            }
            return(RuntimeMethodHandle.InvokeMethod(null, null, signature, true));
        }
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            this.CheckConsistency(obj);
            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                StackCrawlMark  stackMark         = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if ((Assembly)executingAssembly != (Assembly)null && !executingAssembly.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", (object)this.FullName));
                }
            }
            if (obj != null)
            {
                new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, (IRuntimeMethodInfo)this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            Signature signature = this.Signature;
            int       length    = signature.Arguments.Length;
            int       num1      = parameters != null ? parameters.Length : 0;
            int       num2      = num1;

            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num1 <= 0)
            {
                return(RuntimeMethodHandle.InvokeMethod(obj, (object[])null, signature, false));
            }
            object[] arguments = this.CheckArguments(parameters, binder, invokeAttr, culture, signature);
            object   obj1      = RuntimeMethodHandle.InvokeMethod(obj, arguments, signature, false);

            for (int index = 0; index < arguments.Length; ++index)
            {
                parameters[index] = arguments[index];
            }
            return(obj1);
        }
Exemple #5
0
        internal object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture, bool skipVisibilityChecks)
        {
            int length = this.Signature.Arguments.Length;
            int num2   = (parameters != null) ? parameters.Length : 0;
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            this.CheckConsistency(obj);
            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 > 0xffff)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("NotSupported_TooManyArgs"));
            }
            if (!skipVisibilityChecks && ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN))
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            RuntimeType typeOwner = null;

            if (!this.m_reflectedTypeCache.IsGlobal)
            {
                typeOwner = this.m_declaringType;
            }
            if (num2 == 0)
            {
                return(RuntimeMethodHandle.InvokeMethodFast(this, obj, null, this.Signature, this.m_methodAttributes, typeOwner));
            }
            object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature);
            object   obj2      = RuntimeMethodHandle.InvokeMethodFast(this, obj, arguments, this.Signature, this.m_methodAttributes, typeOwner);

            for (int i = 0; i < num2; i++)
            {
                parameters[i] = arguments[i];
            }
            return(obj2);
        }
        public override object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            this.CheckConsistency(obj);
            if (obj != null)
            {
                new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            int length = this.Signature.Arguments.Length;
            int num2   = (parameters != null) ? parameters.Length : 0;

            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 <= 0)
            {
                return(RuntimeMethodHandle.InvokeMethodFast(this, obj, null, this.Signature, this.m_methodAttributes, (RuntimeType)this.DeclaringType));
            }
            object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature);
            object   obj2      = RuntimeMethodHandle.InvokeMethodFast(this, obj, arguments, this.Signature, this.m_methodAttributes, (RuntimeType)this.ReflectedType);

            for (int i = 0; i < num2; i++)
            {
                parameters[i] = arguments[i];
            }
            return(obj2);
        }
        public override object Invoke(System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS  invocationFlags = this.InvocationFlags;
            RuntimeTypeHandle typeHandle      = this.m_declaringType.TypeHandle;

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST | INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(null, this, this.m_declaringType, (uint)(this.m_invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE));
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                }
            }
            int length = this.Signature.Arguments.Length;
            int num2   = (parameters != null) ? parameters.Length : 0;

            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 <= 0)
            {
                return(RuntimeMethodHandle.InvokeConstructor(this, null, (SignatureStruct)this.Signature, this.m_declaringType));
            }
            object[] args = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature);
            object   obj2 = RuntimeMethodHandle.InvokeConstructor(this, args, (SignatureStruct)this.Signature, this.m_declaringType);

            for (int i = 0; i < num2; i++)
            {
                parameters[i] = args[i];
            }
            return(obj2);
        }
Exemple #8
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS invocationFlags = InvocationFlags;

            // get the declaring TypeHandle early for consistent exceptions in IntrospectionOnly context
            RuntimeTypeHandle declaringTypeHandle = m_declaringType.TypeHandle;

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE | INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_CTOR_INVOKE)) != 0)
            {
                ThrowNoInvokeException();
            }

#if FEATURE_APPX
            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
            {
                StackCrawlMark  stackMark = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly caller    = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if (caller != null && !caller.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName));
                }
            }
#endif

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY | INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR)) != 0)
            {
#if !FEATURE_CORECLR
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
#endif // !FEATURE_CORECLR
                RuntimeMethodHandle.PerformSecurityCheck(null, this, m_declaringType, (uint)(m_invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_CONSTRUCTOR_INVOKE));
#if !FEATURE_CORECLR
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR) != 0)
                {
                    new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                }
#endif // !FEATURE_CORECLR
            }

            // get the signature
            Signature sig = Signature;

            int formalCount = sig.Arguments.Length;
            int actualCount = (parameters != null) ? parameters.Length : 0;
            if (formalCount != actualCount)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }

            // We don't need to explicitly invoke the class constructor here,
            // JIT/NGen will insert the call to .cctor in the instance ctor.

            // if we are here we passed all the previous checks. Time to look at the arguments
            if (actualCount > 0)
            {
                Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
                Object   retValue  = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, true);
                // copy out. This should be made only if ByRef are present.
                for (int index = 0; index < arguments.Length; index++)
                {
                    parameters[index] = arguments[index];
                }
                return(retValue);
            }
            return(RuntimeMethodHandle.InvokeMethod(null, null, sig, true));
        }
Exemple #9
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public override Object Invoke(
            Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS invocationFlags = InvocationFlags;

            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0)
            {
                ThrowNoInvokeException();
            }

            // check basic method consistency. This call will throw if there are problems in the target/method relationship
            CheckConsistency(obj);

#if FEATURE_APPX
            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
            {
                StackCrawlMark  stackMark = StackCrawlMark.LookForMyCaller;
                RuntimeAssembly caller    = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if (caller != null && !caller.IsSafeForReflection())
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", FullName));
                }
            }
#endif

            if (obj != null)
            {
#if FEATURE_CORECLR
                // For unverifiable code, we require the caller to be critical.
                // Adding the INVOCATION_FLAGS_NEED_SECURITY flag makes that check happen
                invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY;
#else // FEATURE_CORECLR
                new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
#endif // FEATURE_CORECLR
            }

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != 0)
            {
#if !FEATURE_CORECLR
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_RISKY_METHOD) != 0)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != 0)
#endif // !FEATURE_CORECLR
                RuntimeMethodHandle.PerformSecurityCheck(obj, this, m_declaringType, (uint)m_invocationFlags);
            }

            Signature sig = Signature;

            // get the signature
            int formalCount = sig.Arguments.Length;
            int actualCount = (parameters != null) ? parameters.Length : 0;
            if (formalCount != actualCount)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }

            // if we are here we passed all the previous checks. Time to look at the arguments
            if (actualCount > 0)
            {
                Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
                Object   retValue  = RuntimeMethodHandle.InvokeMethod(obj, arguments, sig, false);
                // copy out. This should be made only if ByRef are present.
                for (int index = 0; index < arguments.Length; index++)
                {
                    parameters[index] = arguments[index];
                }
                return(retValue);
            }
            return(RuntimeMethodHandle.InvokeMethod(obj, null, sig, false));
        }