Reputation: 10055
Im an experienced .NET developer for Windows but im just beginning looking into Xamarin to build for android. Im using VS 2015.
I have added a DLL to my Visual Studio project (Lets call it MyDll1.dll) MyDll1.dll has some dependencies on MyDll2.dll.
Usually for a Windows solution the compiler does not care if MyDll2.dll has been added to the project or not because the code just references MyDll1.dll.
However when i tried to compile a simple dll in Xamarin it is giving an error compiling.
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'MyDll2, Version=2.5.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'MyDll2.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute() App1
So thats all fine i can add MyDll2.dll as a reference except the problem is that Mydll1.dll relies on about 40 other dlls. And those 40 dlls rely on other dlls etc. They are all there are runtime but are they really needed at compile time?
Upvotes: 1
Views: 682
Reputation: 3678
You'll want access to the assemblies and their references.
What Xamarin's compiler is doing is linking your assemblies, so it needs the actual files so it can pull out the metadata and IL. You can disable the linker in your project's properties, but that will result in a much larger app package that may be able to run as long as you never go down any code paths that need the missing assembly to be JITted. Plus, since JITting is Android-only, it probably won't work under iOS (iOS projects are linked ahead of time due to Apple's policies about interpreted code).
Let's take a moment to talk about the black magic Xamarin is performing during the compilation and packaging phase. Quite a long time ago, the MonoTouch/MonoDroid (which is what Xamarin's technologies were originally named) teams decided to eliminate the complications that would arise from a shared runtime, and made it so that the runtime and assemblies would be bundled into your app's package. While this made application deployment MUCH simpler, it had the negative side effect of exploding the size of your apps' packages. To work around this, they developed a really neat feature: a linker that analyzes the usage of the code in the assemblies that your application references and trims out any code that is not being used. In practice, this results in a pretty significant reduction in your app's size, as code/assemblies you never use are omitted from the package. In order to be able to do this, though, the compiler needs to get its hands on the assemblies.
Upvotes: 1