F
FBU
Hi,
I'm writing a C# application for my pocket pc in which i would like to load
dynamically dll (kind of plugins).
In the following piece of code, the load of the assembly (.dll) works
perfectly and my 'assembly' variable seems to be properly initialized. But,
once i call the function GetTypes(), an exception (TypeLoadException) is
thrown.
I don't find any good reasons why i get this exception...
Any help would be very much appreciated.
Thank you!
Frédéric de Buisseret.
public static object GetModuleFromDevice(ArrayList modules)
{
string path =
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetN
ame().CodeBase);
path += @"\modules";
string[] files = Directory.GetFiles(path, "Module*.dll");
Assembly assembly;
foreach (string file in files) {
assembly = Assembly.LoadFrom(file);
if (assembly == null)
continue;
object module = null;
try{
// look in assembly types for our class
Type[] types = assembly.GetTypes(); // Exception
here
foreach (Type definedType in types) {
if (!definedType.IsClass)
continue;
if (definedType.Name.Substring(0, 7).CompareTo("Module_") ==
0) {
module = Activator.CreateInstance(definedType);
break;
}
}
}
catch (Exception e) {
...
}
.....
I'm writing a C# application for my pocket pc in which i would like to load
dynamically dll (kind of plugins).
In the following piece of code, the load of the assembly (.dll) works
perfectly and my 'assembly' variable seems to be properly initialized. But,
once i call the function GetTypes(), an exception (TypeLoadException) is
thrown.
I don't find any good reasons why i get this exception...
Any help would be very much appreciated.
Thank you!
Frédéric de Buisseret.
public static object GetModuleFromDevice(ArrayList modules)
{
string path =
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetN
ame().CodeBase);
path += @"\modules";
string[] files = Directory.GetFiles(path, "Module*.dll");
Assembly assembly;
foreach (string file in files) {
assembly = Assembly.LoadFrom(file);
if (assembly == null)
continue;
object module = null;
try{
// look in assembly types for our class
Type[] types = assembly.GetTypes(); // Exception
here
foreach (Type definedType in types) {
if (!definedType.IsClass)
continue;
if (definedType.Name.Substring(0, 7).CompareTo("Module_") ==
0) {
module = Activator.CreateInstance(definedType);
break;
}
}
}
catch (Exception e) {
...
}
.....