In the code there exists exactly one type that implements IResourceConverter. That's what the two following linq statements are looking for. The former does not find it. The latter does. However they both are equivalent syntaxes (or at least should be!).
Linq Statement 1:
List<Type> toInstantiate = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => typeof(IResourceConverter).IsAssignableFrom(type)
&& type != typeof(IResourceConverter))
.ToList();
This returns 0 results.
Linq Statement 2:
I have left the linq intact except for the where clause, which I broke out and did the equivalent with a foreach loop
List<Type> toInstantiate = new List<Type>();
List<Type> allTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.ToList();
foreach (Type t in allTypes)
{
if (typeof(IResourceConverter).IsAssignableFrom(t)
&& t != typeof(IResourceConverter))
toInstantiate.Add(t);
}
In this case toInstantiate has 1 result ... exactly what I would have expected.
Any explanation for this weird behavior?