So I have a C# project and I'm trying to add USB functionality to it via the Silicon Labs CP2112 USB to i2c bridge. They provide drivers as 2 .dll files: SLABHIDtoSMBus.dll and SLABHIDDevice.dll (which apparently is needed at runtime). I've also found a SLABCP2112.cs file that is supposed to allow the dll to be used in C#.
I've added the SLABCP2112.cs to my project successfully and Intellisense recognizes the functions. The problem is that when I run the program it always throws an exception that the SLABHIDtoSMBUS.dll is not found(System.DllNotFoundException). I've tried moving the dll to various locations such as the main project folder, the 'USB' folder in the project where I've included the SLABCP2112.cs, the Windows SysWOW64 folder and finally in the c#'s projects 'bin' folder.
Placing it in the bin folder still throws an exception but changes the error to a bad image error or something similar. For good measure I've tried to add the .dll's as References in the project but this causes an error "invalid or unsupported type".
I'm assuming the problem is still that the compiler doesn't know where to look for the dll files, so where should I put them? Or if not, how do I get this working?
Related
I am currently developing a program that uses the Ghost Script DLL, by importing it as so:
[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
Now, when I set the project in my solution that uses this directly (located in the directory...\source\repos\uo_test_viewer\omr_scanner\omrmarkengine-master) as the startup project, everything works fine. However, when I change my startup project to a project located in ...\source\repos\uo_test_viewer\UOTestViewer, I get the following error:
The gsdll32.dll wasn't found in the default search path or is not in correct version
(doesn't expose required methods). Please download at least the version 8.64 from the original website.
The only thing that is being changed is that when I set the project that makes this work as the startup project, I am running it directly -- where as with the project that doesn't work, I am creating an object of the form that uses the Ghost Script implementation. Does anybody know what the issue is?
I believe that I have provided all the necessary information, but please let me know if anything more is required. Thank you in advance for your answers!
DllImport looks first in the current working directory, then in the search path (the $PATH) environment variable).
When you start your application in the folder which contains the Ghostscript DLL, then the Windows API call DllImport looks in the current working directory and finds the Ghostscript DLL, so it loads it.
When you start in a directory which does not contain the Ghostscript DLL, then DllImport looks in the Current Working Directory, and does not find the DLL. It then searches the search path, which presumably does not find a Ghostscript DLL, so you get an error.
You either need to be sure the current working directory has a copy of the Ghostscritp DLL, or the DLL is on the search path, or you need to supply a fully qualified path to the Ghostscript DLL in the first argument to DllImport.
In case you are considering distributing this application, please read the AGPL license to ensure that you comply with the terms for using Ghostscript.
my visual studio project has some includes (i use the .net framework 4.6.1).
So I wanted to do a loader in .net 2.0 for unpacking the needed files without admin rights into a user folder with the EXE together.
My idea was to add them as type "FILE" resource into the "loader" project and then extract them as a file again in the user directory together with the .net 4.6.1 EXE. As soon I add one of the files to my NET 2.0 loader project as resource in the designer, the whole project is broken and spits out errors, which I do not understand.
How I can add a complex file as a resource in my project (DLL / EXE)? Simple TEXT-Files work so far. (The extracting routine works also). I get the error right after adding a binary dependency file (DLL) like "System.Data.dll". It says after adding the resource that I have a wrong reference or something alike. The project becomes immediately unusable after it with that error persisting. If I delete the file out of the resource again, the error persists. I have to start all over again with the project.
Any ideas?
I am trying to build a project in C# which uses some unmanaged dll files (MSVCRT.DLL, DFORRT.DLL, ...). There is no direct reference to the MSVCRT.DLL file in the project(this file is referenced by another dll and not directly by my program)
I want this dlls to be copied to bin directory. if i set build action to Content i get this error on run time:
The procedure entry point _wcstoui64 could not be located in dynamic link library msvcrt.dll.
Which is weird. I cant use other build actions because i want my dlls to be published too(Build action=None wont cause any error but doesn't let me to publish my dlls)
If i completely remove all references to all the dlls and treat them like data files, or pictures(files that are not used in code but should be copied to the output) again i get the same error.
What is causing the problem? how can i publish my dlls?
I'm making a programm on C# language and i'm using a special Dll file where storing class with methods that i'm using. At the project i added Dll file as a reference and then print using "library_name" at the code. It's perfectly work on my computer where i'm making it (where is visual studio) and it's also great working on another computer. But my program didn't working at virtual machine that located on second computer. When i'm trying to open it i had an exception like:
"Could not load file or assembly 'spd_lib, Version=1.0.4244.21567, Culture=neutral,PublicKeyToken=null" or one it's dependencies. The system cannot find the file specified."
Somewhere i read that .csproj file had a string where storing all the project's references, so i tried to modify it and give absolute path to the library that located on virtual machine, but it didn't working anyway and had the same exception. Can you please recommend me something to do with it ?
Forgot to say, that my program is on WInForms, so it's perfectly opening and working on virtual machine, but when i press button (there is event where i declare an object of class that located at Dll file) it's had exception and crashed. So, i'm afraid it's not .Net framework problem :/
The virtual machine where you are hosting the application, does it have .Net framework installed?
There are system dlls which are installed in your machine as you have visual studio installed, but the virtual machine might be missing those.
The dll has to be present on the Virtual machine in order for your program to work. To do it you have to mark it as Copy Local in the Visual Studio Preferences window for this particular dll (press F4 when your reference is selected) - when you do it it will be copied to the bin folder (or to any other folder when you Publish your application).
If it doesn't work you need to check from where the application requests this file. For this task you can use fuslogvw or just check it with Process Monitor.
I'm having a problem with a third party C# class library:
The given .net dll requires additional files to be in the same directory than the .dll (config files etc.).
When I load the library as reference into asp.net project everything works smoothly until first call to the library. I get exceptions from the library saying that the required files are missing.
Now the question is where should I put those required files into? I've tried obj/debug/, bin/ and including the files in the project and selecting "Always copy to output directory", but none helped.
I guess it's something to do with IIS and its way of handling the reference/additional files?
Edit: It's working fine in Windows Forms application, but not in ASP.NET web application.
You can view source code of external class library with iLSpy or Reflector to find how exactly additional files are referenced.
It's can be an application execute path (so it must be IIS shadow copy directory) or GAC.
For that you need to read the documentation. The method throwing the error should be expecting the file in some other folder other than bin, debug or obj.