I'm trying to scan an assembly for types implementing a specific interface using code similar to this:
public List<Type> FindTypesImplementing<T>(string assemblyPath)
{
var matchingTypes = new List<Type>();
var asm = Assembly.LoadFrom(assemblyPath);
foreach (var t in asm.GetTypes())
{
if (typeof(T).IsAssignableFrom(t))
matchingTypes.Add(t);
}
return matchingTypes;
}
My problem is, that I get a ReflectionTypeLoadException
when calling asm.GetTypes()
in some cases, e.g. if the assembly contains types referencing an assembly which is currently not available.
In my case, I'm not interested in the types which cause the problem. The types I'm searching for do not need the non-available assemblies.
The question is: is it possible to somehow skip/ignore the types which cause the exception but still process the other types contained in the assembly?
AppDomain.CurrentDomain.GetAssemblies()
, this works on my machine but not on other machines. Why the heck would some assemblies from my executable not be readable/loaded anyway ?? – Intelsat