I need to create Dynamic T using interface. But I am getting "Type Casting" error. Here is my code :
interface IEditor { }
class Editor : IEditor { }
class Test<T> { }
Now the will be dynamic so I am using this code below :
Test<IEditor> lstTest = (Test<IEditor>)Activator.CreateInstance(typeof(Test<>).MakeGenericType(typeof(Editor)));
I am getting following error
Unable to cast object of type 'CSharp_T.Test`1[CSharp_T.Editor]' to type 'CSharp_T.Test`1[CSharp_T.IEditor]'.
This error is not compilation error but I am getting run time error.