By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Another super fun problem

P: n/a
I've been playing around with assemblies and I've run into quite the little
issue.

if you load your .dll up into a byte[] array, and your .pdb into another
byte[] array, then use Assembly.Load(array1, array2); It will load fine, but
if this file you're loading into byte arrays, loads up another dll in the
same manner, that is manually referencing your first dll, it's going to give
you an invalid cast if you try to cast an object off Assembly.CreateInstance,
you can enter the debugger, watch it, create it yourself, play around with
it, no problem at all, but if your memory loaded dll tries to load a second
dll in memory that references the first one (by file instead of memory), it's
going to throw this because it's referencing the real dll that's not even
loaded.

I've been reading and messing with this for a while, one solution is to
create a new app domain, load the assembly in it, then unload the app domain,
which, will then unload your assembly and make your whole situation rainy
again.

I then came up with an idea to save the actual assembly data (in the two
byte[] arrays) then after I loaded the second assembly, I could call
LoadModule on it, which I really don't get, because Load() asks for byte[]'s,
LoadFrom() asks for a filename, but LoadModule asks for a filename AND byte
arrays, no clue about the reasoning on that one, but all I'll ever get from
LoadModule is "invalid filename" or "filename cannot be null". I debugged
into it and the filename it said for that assembly was a different dll in my
application, the last one that was loaded, even though it had almost nothing
at all to do with the assembly I loaded from the byte[]'s.

I'm incredibly tired after spending quite some time trying to figure this
one out, if anyone has any ideas or suggestions, it would be greatly
appreciated, I feel like I'm on the verge of a breakthrough and just can't
seem to make it over this last little hurdle. (or msn,
xe*********@hotmail.com, or aim Xedecimal or yahoo Xedecimal, if it's more
convenient, I'll bring the answer back here when I know it)
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.