Bug 10551 - possible params bug
Summary: possible params bug
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2013-02-21 15:26 UTC by Ronald Crooy
Modified: 2013-02-25 08:12 UTC (History)
4 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 Ronald Crooy 2013-02-21 15:26:43 UTC
I found a bug, which does not occur on windows but does on my mac with mono (latest stable). I was able to narrow it down to this small example. The code was taken from the ServiceStack.Text project, in the file ReflectionExtensions.cs. I stripped out the ifdef stuff that is not relevant to my mac.

I didn't know if this is just a bug in the program or a mono bug, but I thought it best to file it in both projects. So the bug is also viewable on https://github.com/ServiceStack/ServiceStack.Text/issues/281

The exception this will generate is:
> System.InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:MyCtor (): IL_0001: newobj    0x00000001
>   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) [0x0032c] in /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/corlib/System/Delegate.cs:265
>   at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/corlib/System/Delegate.cs:278
>   at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/corlib/System/Delegate.cs:283
>   at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x0002f] in /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:168
>   at MonoBug.MonoBug.GetConstructorMethodToCache (System.Type type) [0x00062] in /Users/ronald/Development/MonoBug/MonoBug/Main.cs:36
>   at MonoBug.MonoBug.Main (System.String[] args) [0x00000] in /Users/ronald/Development/MonoBug/MonoBug/Main.cs:9

using System;

namespace MonoBug
	public class MonoBug
		public static void Main (string[] args)
			//no problem
			GetConstructorMethodToCache (typeof(GoodThings));

			GetConstructorMethodToCache (typeof(BadThings));

		public class GoodThings{
			public GoodThings ( string[] args)

		public class BadThings
			public BadThings (params string[] args)

		public delegate object EmptyCtorDelegate();
		public static EmptyCtorDelegate GetConstructorMethodToCache(Type type)
			var emptyCtor = type.GetConstructor(Type.EmptyTypes);
			if (emptyCtor != null)

				var dm = new System.Reflection.Emit.DynamicMethod("MyCtor", type, Type.EmptyTypes, typeof(MonoBug).Module, true);

				var ilgen = dm.GetILGenerator();
				ilgen.Emit(System.Reflection.Emit.OpCodes.Newobj, emptyCtor);
				return (EmptyCtorDelegate)dm.CreateDelegate(typeof(EmptyCtorDelegate));

			//Anonymous types don't have empty constructors
			//return () => FormatterServices.GetUninitializedObject(type);
			return null;

Comment 1 Zoltan Varga 2013-02-23 17:19:56 UTC
This is a problem in GetConstructor (), GetConstructor(Type.EmptyTypes) seems to match the params ctor on mono, but not on MS.NET.

using System;

public class MonoBug
	public static void Main (string[] args) {
		Console.WriteLine ("D: " + typeof (BadThings).GetConstructor (Type.EmptyTypes));

	public class BadThings {
		public BadThings (params string[] args) {
Comment 2 Marek Safar 2013-02-25 08:12:08 UTC
Fixed in master