- Home /
DllNotFoundException on C# Library in OSX (Phidgets)
I'm having a curious error when trying to import the Phidgets library into my projects on OSX.
The C# DLL is correctly detected by Unity and compiled with the rest of my code. When I sync the project, the DLL's methods are available when I am using the library. However, once I hit play, I get: "DllNotFoundException: phidget21.dll" I've tried putting the DLL everywhere.
I'm not familiar enough with how Unity3D sets it's references to DLLs to properly debug this problem. The reference to the DLL is correctly appearing under References in the SLN. I'm hoping someone that's more familiar with C# DLLs can give me a couple of pointers on why this is occurring.
The Phidgets plug-in is located here: http://www.phidgets.com/docs/Language_-_C_Sharp#OS_X
You don't actually need any Phidgets to see the problem. Just import the DLL following the directions on the site (It's the Phidget21.NET file), then try creating any Phidgets object to see the problem.
One thing of note is the site includes the following directions:
One more thing needs to be done before you can compile and run the
examples. You need to set up a special configuration file so that Mono knows where to find the phidget21.dll. Since Mac does not use dll's you need to redirect it to the appropriate file. Create a new file in the same directory as the example you wish to compile and name it Phidget21.NET.dll.config. Put the following into the file:
<dllmap dll="phidget21.dll" target="/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21"
/>
I haven't the first idea how to target this DLL correctly w/ Unity... Any suggestions?
Answer by Thom Denick · Nov 05, 2013 at 04:20 AM
OK, figured it out.
You need to edit a file within the Unity.app!
Go to the Unity.App file in your Applications -> Right Click Show Package Contents
Now find this file: Contents/Frameworks/Mono/etc/config
That config file is what you need. Open that up in a text editor and add:
<dllmap dll="phidget21.dll" target="/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21" />
Wha lah!
For linux builds the solution is pretty much the same. I added the following to the config file <dllmap dll="phidget21.dll" target="libphidget21.so.0" os="!windows"/>
On linux the config is found in the *_Data folder. For me it was under $$anonymous$$onoBleedingEdge/etc/mono/
.. but it probably depends on your version of unity and .NET
Answer by helderpereira · Mar 29, 2014 at 11:48 AM
Hi
i need some help. When I run the project in Unity 3D, the phidgets run at 100%. But when I do the build for MAC OSX can not connect. The build for Windows works well. Need to copy any files into the package of Mac OSX?
You need to do the same thing, but to the standalone game.app contents that you just built. Go edit the config file found in game.app/Data/$$anonymous$$anaged/etc/mono/ and add the same dll redirection line in the answer above.
Answer by oleprinds · Oct 28, 2014 at 01:09 PM
I created a BuildPostProcessor that automates this for you..
Copy the following class and put it in the /Editor folder in your relevant projects.
This code should run after the build finished:
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Xml;
public class PhidgetOSXBuildPostprocessor
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
if(target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal)
{
//add a dll map to the build..
string dllConfigFileName = pathToBuiltProject+"/Contents/Data/Managed/etc/mono/config";
XmlDocument doc = new XmlDocument();
doc.Load(dllConfigFileName);
XmlElement dllmap = (XmlElement) doc.CreateNode(XmlNodeType.Element, "dllmap", "");
dllmap.SetAttribute("dll", "phidget21.dll");
dllmap.SetAttribute("target", "/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21");
doc.DocumentElement.AppendChild((XmlNode) dllmap);
doc.Save(dllConfigFileName);
}
}
}
Answer by jacasch · May 14, 2018 at 08:03 PM
Thank you so much. Still Usefull in 2018 now with Phidgets 2.2 and unity 2018.1 its a bit different though.
There are 2 Config Files now in "YourUnityProject.App". They are located at: ...\YourUnityProject.App\Contents\Mono\etc\mono ...\YourUnityProject.App\Contents\MonoBleedingEdge\etc\mono
and you need to do modify the dllmap a bit. insert:
<dllmap dll="phidget22" target="/Library/Frameworks/Phidget22.framework/Versions/Current/Phidget22" />
(notice no .dll)
I hope I could help anybody still searching for a solution
Hi there, are you able to share the steps that you took to get Phidgets running on OSX?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers