Load Assemblies from SD card

Hi there,

I’m trying to load an assembly from my SD card to my Panda II but I’m facing a problem : Assembly.Load simply doesn’t seem to work.
I checked my sd card and I have the dll on it.
I tried two ways:


Assembly f = Assembly.Load(path);

And


FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);
byte[] raw = new byte[fs.Length];
fs.Read(raw, 0, (int)fs.Length);
fs.Close();
Assembly f = Assembly.Load(raw);

path being the path to the DLL on the SD card.
I understand that the first one isn’t working as MSDN says I need to provide a “long name” for my dll, but the second should be working.
In both cases all I get from Assembly.load is a NullReference

Has anyone tried this ?
Am I doing something wrong ?

Pyxis 2 (http://www.skewworks.com/products/pyxis 2) and Gadgetos (http://www.skewworks.com/products/gadgetos) both do this, so it is possible. You can take a look at Pyxis 2’s code.

Just loading the assembly won’t do much for you though, you need to instance a class or whatever it is you’re wanting to do with that assembly.

Can you provide more details on what you’re trying to accomplish?

Yes of course loading the assembly isn’t my final objective.

I am making a simple robot and my goal is to put as much code as possible in a seperate assembly, so when i what to update the program running on the Panda II I simply replace the assembly on my sd card without using VS or MFDeploy.

I know I will have to instanciate a class… to have something working but loading the assembly is the first step and so far I am unable to acheive it.

Thanks for the links I’ll take a look at how they did it.

Also know if you’re trying to emulate this VS sort of sits there for a really really long time. The best bet is to press pause, then resume when loading the assembly. For some reason that speeds things up.

Thx I’ll keep that in mind

Ok I’m still missing something.
I took a look at Pyxis2 code and found where it was loading Assemblies.
I tried as they do with

Assembly.Load(File.ReadAllBytes(path));

but it’s still not working.

Is there something else I should take into account to make Assembly.Load work ?

I’m still not sure what you’re looking to have happen.

When you load the assembly the only thing you’ll really see is a readout in VS saying it’s been loaded.

Just adding the assembly won’t launch/start/instance anything.

Yeah I know, that but loading the assembly is supposed to give me back an Assembly object from which I can instanciate my classes. Here all I’ve got from Assembly.Load is a null reference. With a null reference I cannot instanciate the classes that are in my external assembly.

My problem is that Assembly.Load gives me back a null object.

Did I miss something ?

Nope. If you’re getting a null object something is going wrong.

Use a try/catch block and check the error.

Arff even with a try/catch block Assembly.Load doesn’t raise an exception. It just return null, it’s weird.

Maybe it’s the assembly I’m trying to load that is corrupt ? I made a .NET MF class library project is that wrong ?

No that’s perfectly acceptable. My guess would then be that assembly loading isn’t supported on Panda II; I know AppDomains aren’t.

Well, If someone has already achieved that on Panda II, please let me know…

Anyway thanks for all the help you gave me Skewworks, I appreciate it.