Yes, I've read the warning label, and I know that dynamically loading
assemblies is somewhat discouraged. That said, I have an application that
loads assemblies - that's just how it works. It works fine on Windows. Works
fine on Windows CE. I need it to "work fine" on Android, even if it takes some
massaging.
Basically the app is an engine that loads up plug-in DLLs (we'll call it an
Adapter) that meet specific interfaces at run time. Under Windows, it even
detects the appearance of a DLL at any point and goes and loads it - I'm fine
if that's not going to work under Android.
What I'm having trouble getting working is having the Engine load an Adapter
that it knew about at design/compile time but *without* hard coding the name of
that Adapter into the Engine code. I'm fine with adding a reference to the
Adapter to get it to not get linked out, but I really, really don't want to
have to add in the DLL name every time, as the DLLs change with different
deployments, and that would lead to a huge headache.
So I figured that if it's referenced, it would get into the APK, and I could
use reflection to load it like this:
var asm = Assembly.Load("TheAdapterName.dll");
Initial tests show that this works for the Adapter if I just hard code in the
name, but again, I really, really want to avoid that.
So I thought that maybe I could reflect through the references and extract the
name, but oddly, not all references actually show up when I do that. So I do
this:
var refs = asm.GetReferencedAssemblies().Select(a => a.Name).ToArray();
And I get back an array of 14 assembly names. But the assembly (asm) has 16
references, one of which is the Adapter plug-in I need to load. The Adapter is
definitely there - heck I uses Assembly.Load with the full name two lines above
and it resolved.
I thought, ok, maybe I can figure out the "path" to the folder from which I'm
running, and then look for DLLs there and load that way. Ha. After several
hours of trying to figure out a way to get the path that would work under Debug
and Release, I came up with nothing but more grey hair.
Sooooo...... any thoughts on how I might get the name of a DLL that I know is
in my APK, but that I don't "know" the name of at build time (I'm loading them
and looking for interfaces via reflection to detect their "Adapterness").
I'm stuck.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid