<p>No, this is not a question about generics.</p>

<p>I have a Factory pattern with several classes with internal constructors (I don't want them being instantiated if not through the factory).</p>

<p>My problem is that <code>CreateInstance</code> fails with a "No parameterless constructor defined for this object" error unless I pass "true" on the non-public parameter.</p>

<p>Example</p>

<pre><code>// Fails
Activator.CreateInstance(type);

// Works
Activator.CreateInstance(type, true);
</code></pre>

<p>I wanted to make the factory generic to make it a little simpler, like this:</p>

<pre><code>public class GenericFactory&lt;T&gt; where T : MyAbstractType
{
    public static T GetInstance()
    {
        return Activator.CreateInstance&lt;T&gt;();
    }
}
</code></pre>

<p>However, I was unable to find how to pass that "true" parameter for it to accept non-public constructors (internal).</p>

<p>Did I miss something or it isn't possible?</p>

To get around this, couldnt you just alter your usage as such:
```
```
public class GenericFactory<T> where T : MyAbstractType
{
    public static T GetInstance()
    {
        return Activator.CreateInstance(typeof(T), true);
    }
}
```
```
Your factory method will still be generic, but the call to the activator will not use the generic overload. But you should still achieve the same results.