Create generic class instance throws TypeLoadException

Posted by Elisa on Stack Overflow See other posts from Stack Overflow or by Elisa
Published on 2012-09-02T21:34:52Z Indexed on 2012/09/02 21:38 UTC
Read the original article Hit count: 246

Filed under:
|
|

My TestLayer class has the namespace: "BLL.Infrastructure.TestLayer" and is inside the assembly: "BLL"

public class LayerFactory<T, U>
{

  public static IBaseLayer<T, U> Get()
  {
       var obj = Activator.CreateInstance("BLL", "BLL.Infrastructure.TestLayer", new object[]   { (IBaseLayer<T, U>)null });


  }
}

When I run the code the Activator throws an TypeLoadException with no more details

Thats the concrete class it should create:

GenericBaseLayer implements the IBaseLayer.

public class TestLayer<T, U> : GenericBaseLayer<MyRequest, MyInfo.ActionType>
{
  public TestLayer(IBaseLayer<MyRequest, MyInfo.ActionType> layer)
            : base(layer)
   { }
}

What do I wrong?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics