Bug 4183 - Dynamic method owner value is ignored
Summary: Dynamic method owner value is ignored
Alias: None
Product: Runtime
Classification: Mono
Component: Verifier ()
Version: unspecified
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
Depends on:
Reported: 2012-04-02 06:38 UTC by Marek Safar
Modified: 2012-09-03 11:13 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marek Safar 2012-04-02 06:38:59 UTC
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Reflection;
using System.Security;

[assembly: SecurityCriticalAttribute]

class A
	protected A ()

class C
	public static void Main ()
		var ctor = typeof (A).GetConstructors (BindingFlags.NonPublic | BindingFlags.Instance)[0];

		DynamicMethod dynamicMethod = new DynamicMethod (
			MethodAttributes.Public | MethodAttributes.Static,
			typeof (void), new[] { typeof (object) },
			typeof (A),

		ILGenerator il = dynamicMethod.GetILGenerator ();
		il.Emit (OpCodes.Ldarg_0);
		il.Emit (OpCodes.Call, ctor);
		il.Emit (OpCodes.Ret);
		var aa = (Action<object>) dynamicMethod.CreateDelegate (typeof (Action<object>));
		aa (null);

Run on mono with --verify-all

Unhandled Exception: System.Security.VerificationException: Error verifying (wrapper dynamic-method) A:CallCtor_1 (object): Cannot call a constructor outside one at 0x0001
  at (wrapper managed-to-native) System.Delegate:CreateDelegate_internal (System.Type,object,System.Reflection.MethodInfo,bool)
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0 

No error on .net
Comment 1 Rodrigo Kumpera 2012-09-03 11:13:56 UTC
Fixed on master. Only under non-strict mode. So peverify will still flag this as invalid, but the runtime won't.