Reputation: 87
I have project A with reference to project COMMON. In project COMMON i have interface T. I have another DLL B. The B project has reference to project COMMON. COMMON dll is located in both folders.
In project A i load assembly B using Assembly.LoadFromFile. I need to find all types implemented interface T.
var types = (from type in assembly.GetExportedTypes()
where typeof(T).IsAssignableFrom(type) select type).ToList();
I getting 0-size collection. Also i was check types manually in Quick Watch dialog window like :
typeof(T) == assembly.GetExportedTypes()[0].GetInterfaces()[0]
and result was FALSE.
Upvotes: 1
Views: 114
Reputation: 87
OK i solved my problem.
I removed common.dll from plugin folder and i checked "Copy Local" to false. I also using autofac in both projects so for this DLL i was made same steps.
Thanks for Your answers.
Upvotes: 0
Reputation: 1637
Shouldn´t that be
var types = (from type in assembly.GetExportedTypes()
where typeof(T).IsAssignableFrom(type) select type).ToList();
Upvotes: 1
Reputation: 391336
This expression:
X.IsAssignableFrom(Y)
basically ask, can you do the equivalent of this:
X x = expressionOfTypeY;
In your case you're asking this:
ClassType x = expressionOfInterfaceType;
Which is the wrong way around.
Try this LINQ query instead:
where typeof(T).IsAssignableFrom(type)
Upvotes: 2