I am trying to understand the differences between Assembly.Load and Assembly.ReflectionOnlyLoad.
In the code below, I try to find all the objects in this assembly that inherit from this interface:
var myTypes = new List<Type>(); var assembly = Assembly.Load("MyProject.Components"); foreach (var type in assembly.GetTypes()) { if (type.GetInterfaces().Contains(typeof(ISuperInterface))) { myTypes.Add(type); } }
This code works fine for me, but I explored other, perhaps better alternatives, and came across the Assembly.ReflectionOnlyLoad () method.
I assumed that since I am not loading or running any objects, essentially just asking for their definitions, I could use ReflectionOnlyLoad to slightly improve performance ...
But it turns out that when I change Assembly.Load to Assembly.ReflectionOnlyLoad, I get the following error when it calls assembly.GetTypes ():
System.Reflection.ReflectionTypeLoadException:
Unable to load one or more of the requested types. Check out the LoaderExceptions property for more info.
I assumed that the above JUST code reflects and “looks at” the library ... but is this some kind of Heisenberg uncertainty principle in which viewing the library and objects in it actually tries to create an instance in some way?
Thanks Max
reflection c #
Max Schilling Nov 20 '08 at 16:08 2008-11-20 16:08
source share