- Home /
Using a .dll in Unity C#
I am currently working with Unity3D, and need to import a .dll file compiled in VS2008, using .net 2.0. It works perfectly well on the PC version and it works just like I want it to, but it somehow breaks my iOS build. I'm not even using the .dll on mobile devices, and the code linking to the dll (DllImport) is compiled only in the PC build.
I'm getting the following error when building for iOS :
ArgumentException: The Assembly Microsoft.VisualC is referenced by mydll. But the dll is not allowed to be included or could not be found.
I've changed to api compatibility level (in the player settings for all platforms in unity) to .net 2.0, and built my dll targetting the 2.0 .net level as well.
Why is the dll even in my build ? What are the correct steps to import a .dll, maybe I've missed something crucial ?
QUICK EDIT : The .net api compatibility wasn't set correctly in the end for iphone, but I'm still getting some error :
Error building Player: NullReferenceException: Object reference not set to an instance of an object
I think it's during the AOT cross compile phase of the player creation. Maybe someone knows how to deal with this ?
Also, maybe it was unclear in my question, but my DLL uses managed code to be able to access .net functions.
UPDATE : Been working on this a bit on my end, now I'm wondering if there is a way to simply exclude this .dll from my iOS build ? (apart from doing it manually everytime I want to build). I can't seem to find out a way to do this. I've tried stripping, but it doesn't work well with other parts of my application (breaks some things), and now I'm a bit lost. I can manually remove and add it as a workaround but would really like a cleaner solution !
Answer by stevethorne · Jul 17, 2014 at 12:55 PM
Do you have the Windows .dll in an x86 folder, or x86_64 folder? This will tell Unity that it is a Windows specific .dll. Special Folder Names
@stevethorne Just tried that. Still getting a single "Error building Player: NullReferenceException: Object reference not set to an instance of an object" error, with nothing else explaining anything. It seems no matter where I put the .dll in my Assets folder, this error will occur.
Where you have the code referencing that dll in your scripts, do you have them wrapped in #define's for Windows only? That way the code doesn't get compiled when iOS is going?
@stevethorne Yep, using the #if UNITY STANDALONE WIN (those spaces are underscores) tag for all code that references the .dll. First thing I checked, actually !
Your answer
Follow this Question
Related Questions
Can Unity work with a "Managed .NET assembly (NatNetML.dll) for use in .Net compatible clients"? 1 Answer
[iOS] Managed DLL cannot find references to .Net framework DLLs 1 Answer
Unable to pass aws credentials at runtime in iOS 1 Answer
What kind of devices are supported/required to run builds using .NET 4.x scripting runtime? 2 Answers
ML.NET in unity 1 Answer