I am using the code below to load an assembly from a .dll file. Each of the classes contained within are inspected to see if they implement my “IControl” interface.
If they do, I began reflecting them to look at their properties and especially their custom Attributes.
To look at their custom attributes I have to create a Type object passing the AssemblyQualifiedName property as a parameter to the GetType(string) method, because for some reason if i just called GetCustomAttributes() on the typesInAssembly[k] Type object, the if construct inside the foreach...loop would not evaluate to true.
My problem is; The above code works fine on my machine. However, on my colleagues' machines it does not work. I find that the AssemblyQualifiedName property passed in to the GetType(string) method has different version numbers, but don't know why!
I'm afraid I am a newbie at C# and Assemblies, reflection etc.
If anyone could give me any idea why the above code works for me, but not for my colleagues I would be very grateful.
All suggestions appreciated!
Many thanks
Oxy
we are all of us living in the gutter.
But some of us are looking at the stars.
If they do, I began reflecting them to look at their properties and especially their custom Attributes.
To look at their custom attributes I have to create a Type object passing the AssemblyQualifiedName property as a parameter to the GetType(string) method, because for some reason if i just called GetCustomAttributes() on the typesInAssembly[k] Type object, the if construct inside the foreach...loop would not evaluate to true.
Code:
Type[] typesInAssembly = null;
try
{
Assembly myAssembly = Assembly.LoadFrom(myPluginDLLfiles[i].FullName);
typesInAssembly = myAssembly.GetTypes();
}
catch (Exception e)
{
//do something with exception
}
Type tempControl = null;
for (int k=0;k < typesInAssembly.Length;k++)
{
/*See if any of the Types in the assembly implement the IControl interface*/
Type anInterface = typesInAssembly[k].GetInterface("IControl");
if ((anInterface != null) && (typesInAssembly[k].IsClass))
{
ControlDescriptor currentControlD = new ControlDescriptor(filesInDir[i]); //create new ControlDescriptor
/*Needs to be a fully qualified assembly name*/
tempControl = Type.GetType(typesInAssembly[k].AssemblyQualifiedName); //ASSIGNMENT FAILS!!!!
ControlAttribute controlAttr = null;
object[] attributes = tempControl.GetCustomAttributes(false);
foreach (Attribute attr in attributes)
{
controlAttr = attr as ControlAttribute;
if (controlAttr != null)
{
/*set ControlDescriptor properties to those reflected from control*/
currentControlD.Description = controlAttr.ControlDescription;
}
}
}
}
My problem is; The above code works fine on my machine. However, on my colleagues' machines it does not work. I find that the AssemblyQualifiedName property passed in to the GetType(string) method has different version numbers, but don't know why!
I'm afraid I am a newbie at C# and Assemblies, reflection etc.
If anyone could give me any idea why the above code works for me, but not for my colleagues I would be very grateful.
All suggestions appreciated!
Many thanks
Oxy
we are all of us living in the gutter.
But some of us are looking at the stars.