Loading Assemblies dynamically in Compact Framework

  • Thread starter Thread starter shabari
  • Start date Start date
S

shabari

Dear all,

I need to load a assembly at the runtime,,, so i am using

Assembly.LoadFrom("<<path of the dll>>")

But when i try to invoke its methods ,i am getting an Exception

"NotSupported Exception"

Is it not possible to load an assembly at the runtime in Compact Framework ??

Kindly help
 
you have to invoke the constructor before you can invoke
the methods.
Here is some sample code that might help:

public static Product GetProduct(ProductInfo P,
PrivateKey K)
{
Product product = new Product();
string filePath = "Program
Files\\MyProgram\\MyAssembly.dll";

if(File.Exists(filePath))
{
Assembly productAssembly = Assembly.LoadFrom
(filePath);

foreach(Type type in productAssembly.GetTypes())
{
if(type.BaseType.ToString()
== "MyCompany.MyNamespace.Product")
{
try
{

Type[] signature = {P.GetType(), K.GetType()};

ConstructorInfo constructorInfo =
type.GetConstructor(signature);

product = (Product) constructorInfo.Invoke(new
object[] {P,K});
}
catch{}
}

}
}
}
 
Back
Top