Example:
class Program { static void Main(string[] args) { var myClass = Activator.CreateInstance(typeof(MyClass)); } } public class MyClass { internal MyClass() { } }
An exception:
System.MissingMethodExceptionThere is no constructor without parameters for this object.
System.MissingMethodException
There is no constructor without parameters for this object.
Decision:
var myClass = Activator.CreateInstance(typeof(MyClass), nonPublic:true);
I cannot understand why I cannot create an instance inside an assembly with an internal constructor. This constructor must be available inside the runtime assembly. It should work as a public for this assembly.
This is not so impossible. you must say that this is not an audience.
var myClass = Activator.CreateInstance(typeof(MyClass), true);//say nonpublic
The constructor inside your MyClass is internal. Try switching to public
public class MyClass { public MyClass() { } }
or
Pass true for CreateInstance
var myClass = Activator.CreateInstance(typeof(MyClass),true );