How to load dependent assembly?

I have a project processor, and it depends on the other 2 projects.

When I compile the project, I get the dll Processor.dll and another project-dependent dll in the Bin folder. Processor.dll BusinessAction.dll and Repository.dll.

I tried to call a method from Processor.dll by initiating the ProcessRequest class .

Like this

 Assembly processorAssembly = Assembly.LoadFile(path + "Processor.DLL"));

        Type myType= processorAssembly.GetType("Namespace.ProcessRequest");

        myType.InvokeMember("Process", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, submitOfferType, new object[] { 12345 });

The processing method has some logic for processing and storing it in the database.

when I call the procee method using InvokeMember ()

i get exception Failed to load file or assembly 'Namespace.BusinessAction, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null' or one of its dependencies. The system cannot find the specified file.

Am I calling a method?

+3
2

Appdomain , , :

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

:

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    string s = @"C:\lib\" + args.Name.Remove(args.Name.IndexOf(',')) + ".dll";
    return Assembly.LoadFile(s);
}
+6

Assembly processorAssembly = Assembly.LoadFrom(path + "Processor.DLL")); 

DLL

+2

All Articles