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.
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)
Shouldn´t that be
var types = (from type in assembly.GetExportedTypes()
where typeof(T).IsAssignableFrom(type) select type).ToList();
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.