Nuget packaging - can't find dll?

Comments & issues
nm17
Phidgeteer!
Posts: 53
Joined: Mon Nov 27, 2017 3:29 am
Contact:

Nuget packaging - can't find dll?

Post by nm17 »

I have started using Nuget version of Phidgets drivers in my c# WPF application. The app is packaged using VS Installer Projects and then installed usually as an upgrade to previous app version.

The installer project correctly detects Phidget nuget dlls and does put them in the application folder (ie c:\program data...\my app\). However when I start the application I get a binding error from windows (this is a call to enable hardware logging in Phidgets). Basically it states it can't find the DLL which is weird as the DLL is in the folder. I use other (non-Phidget) Nuget packages in the same project and that all works well.

I thought that there may be a clash as I had Phidget Control Panel installed so I uninstalled that - but no luck.

What I found resolves the issue is: uninstall both Phidget CP and my app, then install my app, then install Phidget CP (must match version to nuget package!) and then it works.

I am wondering if I am missing a trick here, I have to confess I am not a Nuget guru and as I don't have problems with other packages thought it may be something Phidgets specific...

Do I need to do something specific eg ask Installer Project to register Phidgets as COM module or anything else to make Nuget work with or without Phidget CP. Ideally I would like my software to work without having Phidgets CP on the device but if CP is installed then it should not break/clash with whatever nuget-Phidgets dll is installed.

Code: Select all

Exception: System.DllNotFoundException: Unable to load DLL 'phidget22': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Phidget22.Phidget22Imports.PhidgetLog_enable(LogLevel level, IntPtr destination)
   at Phidget22.Log.Enable(LogLevel level, String destination)
   at S.SC.HardwareLog.EnableHardwareLogging(Boolean enable, String logName)
   at Phidget22.Phidget22Imports.PhidgetLog_enable(LogLevel level, IntPtr destination)
   at Phidget22.Log.Enable(LogLevel level, String destination)
   at S.SC.HardwareLog.EnableHardwareLogging(Boolean enable, String logName)
I have used dll dependency walker and it appears that Phidget22.Net.dll is referenced correctly *but* this dll itself references system-wide Phidgets dll which I guess requires Phidgets CP (matching version) to be installed??
phidgets nuget dll dependency issue.PNG
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Nuget packaging - can't find dll?

Post by Patrick »

The Phidget nuget includes both the .NET dll (Phidget22.NET.dll) and the C dll (both 32-bit and 64-bit) (dll/x64/phidget22.dll, dll/x86/phidget22.dll) - you'll need to make sure the installer is including the C dll, and it needs to be in the dll/(x64|x86)/ folder with respect to the .NET dll. If the .NET dll cannot find the C dll included in the nuget, it will try to find it elsewhere, so it could find the system-wide one as installed with the control panel.

-Patrick
nm17
Phidgeteer!
Posts: 53
Joined: Mon Nov 27, 2017 3:29 am
Contact:

Re: Nuget packaging - can't find dll?

Post by nm17 »

Thanks Patrick I assume the dlls you refer to are located in project's bin folder under Release/dll/...

So if I need to manually install them, do I just copy them to c:\windwos\SysWow64 or somewhere else or do I ask installer to register them as COM? How do I decide if I should install x64 or x86?

Normally when I include a nuget package VS Installer projects "knows" what to do for that nuget package... It feels like I need a special routine/code to figure out which dll (x64 or x86) should I install and then either copy or register it appropriately... or am I overcomplicating it? :)
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Nuget packaging - can't find dll?

Post by Patrick »

You shouldn't be installing anything to the system folders. Just keep the .NET and C dlls with your program. As long as the C dlls are in their dll folder in the same folder as the .NET dll - the .NET dll will be able to find them. It chooses 32 or 64 bit at runtime.

-Patrick
Olivia232425
Fresh meat
Posts: 1
Joined: Thu Mar 18, 2021 5:17 am
Contact:

Re: Nuget packaging - can't find dll?

Post by Olivia232425 »

Usually when I include the nuget package the VS Installer projects "know" what to do with that nuget package ... I feel like I need a special procedure / code to figure out which dll (x64 or x86) or additional software might be a kind of employee monitoring software so that they read the code for me ... I should install this and then either copy or write accordingly ... :)
mike_gormack
Fresh meat
Posts: 1
Joined: Mon Nov 22, 2021 8:17 pm
Contact:

Re: Nuget packaging - can't find dll?

Post by mike_gormack »

Same issue here with missing .dll file warning. The issue appears to be the installer doesnt copy the dll subfolder by default and needs to be manually added to the install directory by the installer process
ralphduke724
Fresh meat
Posts: 1
Joined: Thu Jan 27, 2022 7:33 am
Contact:

Re: Nuget packaging - can't find dll?

Post by ralphduke724 »

I have the same issue. Any tips for solution?
nm17
Phidgeteer!
Posts: 53
Joined: Mon Nov 27, 2017 3:29 am
Contact:

Re: Nuget packaging - can't find dll?

Post by nm17 »

I have limited success with configuring my Set-up software to "manually" create application/dll folder and copy all Phidgets *.dll from my bin/Release folders to the application/dll folder.

This works in some situations but I still find it breaks on upgrades occasionally and also sometimes when there is a Phidgets Manager installed on the computer.

I haven't had time to get in-depth understanding of how this works (and why I need to copy files manually) but it feels there is a bug lurking there as the performance is patchy.
nm17
Phidgeteer!
Posts: 53
Joined: Mon Nov 27, 2017 3:29 am
Contact:

Re: Nuget packaging - can't find dll?

Post by nm17 »

I wonder if there is a way to mark Native DLLs in Nuget so they are detected as dependency by Visual Studio Installer Projects.

I was reading https://developercommunity.visualstudio ... e-a/419838 and they mention that native Dlls should be marked as 'Content' so to get included automatically.
If you look inside it at the file RoyaleCameraWrapper.3.20.0.62-PreRelease\build\RoyaleCameraWrapper.targets you'll see it's adding these assemblies to project as items of type 'None'. If you change this to 'Content' and you have "Content Files from ClassLibrary2" included in your installer project you'll see that they are successfully included in the msi. However, even in this case you'd need to include content files directly from the project with the NuGet reference, including content files from a project that has a reference to that project isn't good enough.
sakdene05
Fresh meat
Posts: 1
Joined: Wed Sep 07, 2022 1:50 am
Contact:

Re: Nuget packaging - can't find dll?

Post by sakdene05 »

Thanks Patrick I assume the dlls you refer to are located in project's bin folder under Release/dll/...
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests