- Home /
[iOS] Managed DLL cannot find references to .Net framework DLLs
Question
I need to include in my project a set of open-source libraries for making queries against OData REST APIs. The libraries come from Microsoft (https://www.nuget.org/packages/Microsoft.OData.Client) and target .Net 4.5. I can include the libraries in editor and on UWP with no issues. However, when I try to make a build for iOS I start getting errors saying:
ArgumentException: The Assembly System.Diagnostics.Tools is reference by Microsoft.OData.Edm(…) but the DLL is not allowed to be included or could not be found.
Looking up similar questions I found that copying that required DLL from the Mono Facades directory into the Unity assets directory should fix the issue. So I copied that DLL only to find that another DLL was required (System.Resources.ResourceManager). So I copied that one and repeated the process a bunch more until the build completed successfully. In the end I had to copy a total of 23 DLLs to get it to work!
What interests me is WHY I had to include some of the DLLS. Most of the required DLLs are part of mscorlib.dll and System.dll, which should already be included by Unity. For example, one of the DLLs I had to copy was System.Threading.Tasks. My Unity code (the code in my Unity Assets directory and not in a separate DLL) uses Tasks extensively, so that assembly must already by in the build.
If these assemblies can be referenced by Unity code without explicitly adding them to my Assets folder, why do I need to add them for the DLL? Won't this lead to multiple versions of these assemblies being compiled into my project? Is there something I can do so that I don't have to copy all 23 DLLs into my Assets folder?
More Info:
Unity Version 2017.4.9f1 Scripting Runtime Version: Experimental .Net 4.6 Equivalent Scripting Backend: (IL2CPP on ios, .Net on PC and UWP) Api Compatibility Level: .Net 4.6
DLLs I had to include:
System.Collections
System.ComponentModel
System.ComponentModel.EventBasedAsync
System.Diagnostics.Debug
System.Diagnostics.Tools
System.Dynamics.Runtime
System.Globalization
System.Linq
System.Ling.Queryable
System.Net.Requests
System.Reflect
System.Reflection
System.Reflection.Extensions
System.Resources.ResourceManager
System.Runtime.Extensions
System.Runtime.InteropServices
System.Runtime.Serialization.Primitives
System.Text.Encoding
System.Text.Encoding
System.Text.Encoding.Extensions
System.Text.RegularExpressions
System.Threading
System.Threading.Tasks
System.Xml.ReaderWriter
Answer by dsanteugini · Jan 11, 2019 at 10:45 AM
I had the same issue in the past.
If you have a dll developed in pure c# (and later compiled to a dll) using other dll created in c# too, any library will work on your project. But, if you're trying to use a library that uses a non-c# dll (for example, a c++ library) it won't work. You will need to recompile all non-c# dll to a ios library (it creates a .so file) and these libraries needs to be static-linked. Otherwise, it won't works.
System.Diagnostics.Tools -> I'm pretty sure that this library uses a non-c# dll
Regards,
Dani