Bug 23433 - Activator.CreateInstance Method (Type, Object[]) is broken on mono
Summary: Activator.CreateInstance Method (Type, Object[]) is broken on mono
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-09-27 09:28 UTC by Mike
Modified: 2015-02-27 06:07 UTC (History)
3 users (show)

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


Attachments
C# source reproducing the issue (292 bytes, application/octet-stream)
2014-09-27 09:28 UTC, Mike
Details


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:
Status:
RESOLVED FIXED

Description Mike 2014-09-27 09:28:42 UTC
Created attachment 8216 [details]
C# source reproducing the issue

using System;
namespace ParamsConstructor
{
	class TestClass{
		public TestClass(params object[] parameters)
		{
		}
	}
	class MainClass
	{
		public static void Main (string[] args)
		{
			var temp=Activator.CreateInstance(typeof(TestClass),1,2,3,4,5);
			GC.KeepAlive (temp);
		}
	}
}

This tiny program is working on .Net 4.5 without any problems - but it fails when executed on mono with the following exception:

[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: No constructor found for ParamsConstructor.TestClass::.ctor(System.Int32, System.Int32, System.Int32, System.Int32, System.Int32)
  at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00180] in /private/tmp/source-mono-mac-3.10.0-branch/bockbuild-mono-3.10.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.10.0/mcs/class/corlib/System/Activator.cs:301 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in /private/tmp/source-mono-mac-3.10.0-branch/bockbuild-mono-3.10.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.10.0/mcs/class/corlib/System/Activator.cs:232 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /private/tmp/source-mono-mac-3.10.0-branch/bockbuild-mono-3.10.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.10.0/mcs/class/corlib/System/Activator.cs:227 
  at ParamsConstructor.MainClass.Main (System.String[] args) [0x00001] in /Users/user/repo/ParamsConstructor/Program.cs:15 

Mono JIT compiler version 3.10.0 ((detached/ac51002 Wed Sep 17 18:34:00 EDT
2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors.
www.mono-project.com
    TLS:           normal
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug 
    LLVM:          yes(3.4svn-mono-(detached/e656cac)
    GC:            sgen

Mono C# compiler version 3.10.0.0

The same issue applies to linux installations.
Comment 1 Marek Safar 2015-02-27 06:07:18 UTC
Fixed in master