Quantcast
Channel: Xamarin.Mac — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 1429

Dll import broken after upgrading to unified API / Visual Studio For Mac

$
0
0

Background: I have an macOS application that allows a device to sync data from a remote web server via USB. In order to facilitate this USB syncing I use the HIDAPI library which is mapped in code through DLLImport.

Problem: Recently I have upgrade my macOS application to the Xamarin Unified API utilizing Xamarin.Mac Full. I am also now building the application using MSBuild instead of MDTool as we use Visual Studio for Mac and no longer Xamarin Studio. After this upgrade process I am now seeing System.DllNotFoundExceptions when attempting to access any of the methods that I map from the HIDAPI dylib file via dll import.

Code: In order to map the dll correctly I do the following
1) Copy the libhidapi.0.dylib file into the *.app/contents/MonoBundle folder
2) Add at the following code block to app config for the library that consumes libhidapi between some configuration tags:

<dllmap dll="libhidapi" target="libhidapi.0.dylib" os="osx"/>

3) Create a wrapper class where I call DLLImport and map the methods that I need into C#, an example of which follows:

    internal const string HIDAPILIB = "libhidapi"; 
    internal const CallingConvention CC = CallingConvention.Cdecl;
    internal const CharSet CHARSET = CharSet.Unicode;

    static hidapi ()
    {

    }

    [DllImport(HIDAPILIB, CallingConvention = CC, SetLastError=false, CharSet=CHARSET)]
    internal static extern int hid_init();

Things I've Tried: I've tried to fix this problem by adding @executable_path/contents/MonoBundle to the target portion of my app config as displayed above, I've even tried to hardcode the exact location of the library in the app bundle on my local machine to try and get it to work locally to no avail. All of my efforts result in a dll not found exception. Any assistance would be greatly appreciated.


Viewing all articles
Browse latest Browse all 1429

Latest Images

Trending Articles



Latest Images