minor reflection loadfrom/loadfile quirk

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



can anyone help me with the following

bellow is a routine i use that works, that will load an assembly from
a dll class from the HDD, and instantiate a form to be used to
control a device.

What is listed bellow works but

1 . before i got it to work this line

// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);

i was using .LoadFrom(devDir + devicefile);


can anyone tell me why the loadFrom did not work properly. It worked
for the first file location path i sent into the subroutine, after the
prog first runs, but every subequent file/location i tried to load,
the new file location is correctly passed into the routine, BUT using
loadfrom would only ever instantiate/load the first one loaded in the
program running session. It would not load anything other that the
first one passed in.

As i said what i have bellow works, but didnt LOadFrom work ?









private void loadDeviceInterfaceToSerialPort(int port,String
devicefile)
{

Assembly deviceInterfaceAssembly = null;


// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);

//
tbIPLinkFeedback.AppendText(deviceInterfaceAssembly.Location +
"\r\n");

// tbIPLinkFeedback.AppendText(devDir + devicefile +
"\r\n");

if (deviceInterfaceAssembly == null)
MessageBox.Show("not loaded");

// Get all types in assembly.
//ClassLibrary1.Form1
Type[] deviceInterfaceType =
deviceInterfaceAssembly.GetTypes();
//
tbIPLinkFeedback.AppendText(deviceInterfaceType[0].FullName + "\r\n");


//
tbIPLinkFeedback.AppendText(deviceInterfaceType[0].FullName);
//
tbIPLinkFeedback.AppendText(deviceInterfaceType[0].Name);

// Use late binding to create the type.

// tbIPLinkFeedback.AppendText(testform.Name);

ipLink.SetSerialPortDeviceInterface(port,
(Form)deviceInterfaceAssembly.CreateInstance(deviceInterfaceType[0].FullName));

ipLink.GetSerialPortDeviceInterface(port).MdiParent =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPosition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBorderStyle =
FormBorderStyle.None;



ipLink.GetSerialPortDeviceInterface(port).Size = new
Size(400, this.ClientRectangle.Height);
ipLink.GetSerialPortDeviceInterface(port).Location = new
Point(540, 0);

ipLink.GetSerialPortDeviceInterface(port).Show();


}
.


Quantcast