How do I create an object with Generics via reflection in c#
<p>I need to find all the instances of objects which implement interface IFOO.
Then create the object and find some values of some properties of the object.</p>

<pre><code>public interface IFoo
{

}
public class FooModel
{
    public string Code { get; set; }
}


public class Foo&lt;FooModel&gt; : IFoo
{

}

public class Create{

    public void CreateInstances()
    {
        var itype = typeof(IFoo);
        var types = (from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
                     from assemblyType in domainAssembly.GetTypes()
                     where itype.IsAssignableFrom(assemblyType)
                     select assemblyType).Where(m =&gt; m != itype);
        foreach (var type in types)
        {
            var genericArgs = type.GetGenericArguments();
            var makeme = type.MakeGenericType(genericArgs);
            var newObject = Activator.CreateInstance(makeme);

        }
    }
}
</code></pre>

<p>However when the newObject is created I get the following error:</p>

<p>Cannot create an instance of Foo`1[FooModel] because Type.ContainsGenericParameters is true</p>