Take the 2-minute tour ×

is it possible to load an dll with Assembly.Load when it's in the asset folder?

I have platform specific dll's for windows and android. I tried to use the android specific dll as asset (also in the build action), but when I try to load it into my app it's not found (I used the path: file:///android_asset/mydll.dll), and this only happens, if i build the app as release, in debug i get the necessary paths to load the library, but not from the assets folder.

What can I do? Is there another place, where I can put my dll to be loaded from my app?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Here is an example of writing out assemblies to a Plugins folder and then reading them in and loading at runtime.

Make sure that you have your assemblies that you want to have go to the Assets folder set to a Build Action of AndroidAsset. See screenshot below.

Please Note: You might need to change the extension to .mp3. See here. I didn't have this issue though.

enter image description here

Once you do that, you should be able to get the assets by using the Asset Manager. You can load them up or do whatever with them. Here is a sample of reading them into memory and the writing out the name.

const String pluginPath = "Plugins";

var pluginAssets = Assets.List(pluginPath);
foreach (var pluginAsset in pluginAssets)
    var file = Assets.Open(pluginPath + Java.IO.File.Separator + pluginAsset);

    using (var memStream = new MemoryStream())

        //do something fun.
        var assembly = System.Reflection.Assembly.Load(memStream.ToArray());
        Console.WriteLine(String.Format("Loaded: {0}", assembly.FullName));


In release mode, please be mindful that the Mono for Android is going to perform a static analysis of your libraries to perform a size optimization. If you are loading assemblies after this, then you may not have features that should have been included. The screenshot below shows the standard linking configuration for a release build. There are some flags and configurations that you can add to your code to help prevent linking (Xamarin Docs on Linking), but I am not sure that there will be too much that you can do for dynamically loaded libraries.

Mono for Android - Release Linking

share|improve this answer
Thx, it works now to load the assembly, in a debug build I can use platformAssembly.CreateInstance, but in a release build I only get the Error: The classes in the module cannot be loaded. Did you also experience this problem? –  Netbus Jan 24 '13 at 14:59
Netbus, I updated my answer above. I believe the issue you are having is due to linking that is being done by the release build. Try turning linking off in the Properties > Mono Android Options screen and see if you still get the error. –  Mike Stonis Jan 24 '13 at 20:06
add comment

This is not a direct answer to your question - I've no idea about loading assemblies from assets.

However, I do have quite a lot of experience of loading plugins in mvvmcross.

In mvx, we load platform specific plugins on droid by simply adding the dll as a refernce to the ui project and then calling Assembly.Load at runtime. This seems to work well.

Further, the same approach can be used in full windows applications - eg Wpf.

However, the same approach cannot be used on MonoTouch, Wp or WinRt - JIT and security/sandbox restrictions mean that you have to use some ui platform code to actually inject a code reference instead of using assembly.load. For more info, see http://slodge.blogspot.co.uk/2012/10/build-new-plugin-for-mvvmcrosss.html?m=1

share|improve this answer
add comment

Your Answer


