DllNotFoundException with DllImport in Mono on Mac - c#

I'm trying to use DLLImport in my Mono Mac project in order to use my own .dylib but I get the DllNotFoundException. I'm guessing it has something to do with my .dylib since I'm able to do this with existing .dylib files such as the libmojoshader.dylib.
Here's how I use DLLImport
[DllImport("libtestDylib.dylib")]
static extern int libsum(int a, int b);
I then call the libsum function in order to see if it works.
I've found that running the app through the terminal with the MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono myGame.exe command is a great way to debug issues like this, however I can't get my app .exe to run. I've tried using both the .exe in build folder and the one in the .app/contents/MonoBundle, I've also tried running file in .app/contents/MacOs as this is referenced in some places I've found while researching.
The last file throws a "File does not contain a valid CIL image." and the two others "No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file".
So, I would guess that the first step is to manage to run the app through the terminal in order to get proper debug information as for why my .dylib can't be found.
The .dylib I made is an empty BSD C lib made in XNA4.
Edit
I can't even seem to get the existing dylibs to work now.

I found the problem by making a new Mono Mac project with a single c# file which I then compiled through the terminal and ran it with the debug command. With the terminal feedback found out where the program was searching for the .dylib, and that the lib I made was built with the wrong architecture which was simply solved by building for 32-bit systems.

Related

C# Project : Build Folder : Build a project on a computer and run it on another computer

I have a C# project. To run it, I need to provide 2 arguments.
I want to create a build folder, that I can just copy/paste on another computer and run in the future. First, I build the project on a computer, then I copy/paste the build folder on another computer (I use Remote Desktop Connection). The build folder contains executable, configuration file (XML) and .dll files.
When I run the program on the second computer, I had this response on the console : System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {99AEA70E-4D13-44BF-A878-33345CBFCBC8} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I checked .NET Version on both computer and it is the same version.
I tried different case of build (Configuration : Release and Platform : Any CPU/x64/x86).
I saw some things like ClickOnce but I can't use it because of the 2 arguments.
Moreover, to run this project, I use a UI (same for both computer). The UI work on both computer. This update configuration file and run the project. On the first computer (we build the project on this one), the program works correctly. On the second computer, the UI works and when I run the program through UI, I have the issue above.
Are there any solution to fix this issue ?
I found some solution but they are old and they doesn't work.
As mentioned in the comment, you are using a COM Component, which might need to be installed on your second computer as well.
There may be a way, when you locate the references, find the respective DLLs and copy them with your Executable. If you have a look at the RedemptionLoader, Dmitri is doing exactly, what you need to do, to load the types from the DLLs in there.
However, make sure to have everything in one assembly, that uses the types in question, when using them without installing the COM Component. Otherwise you will get weird error messages.
Thanks for your answers. It helps me to understand the issue.
So, this program permits to do some things with Photoshop. On the first computer, I have Photoshop CS6 and on the a second one I have Photoshop CC. To fix the issue, I will create a build folder for Photoshop CS6 and another one for Photoshop CC.
I tried to copy/paste the build folder from the first computer (with Photoshop CS6) on a third computer, with Photoshop CS6 too. This works !
The issue was caused by the version of Photoshop.

C# System.DllNotFoundException

I have a simple application using a product activation system offered by cryptlex (cryptlex.com).
The program works correctly on my computer, but when I try to run the program on another machine it returns this error:
I've already made sure that the dll is inside the executable folder and everything looks OK.
When I remove all part of cryptlex the program works perfectly on any machine (x86-x64)
I used depencywalker to check for errors and found these two in the executable that uses cryptlex:
Windows 7 64bits,
.NET Version: 4.0
You can use Process Monitor to record all file activities of the program. Set a filter for your executable. After reproducing the error, save the log as XML file.
Then run ProcMon Analyzer (note: I'm the author of it). It will analyze the file and give a list of DLLs that were not found.
You could also do that manually, but note that some DLLs may not be found at first, but later be found when looking in the %PATH% environment variable etc. The tool will remove all those entries which have PATH NOT FOUND first but SUCCESS later.
While the DLL is present, have you checked the bitrate?
Most C# projects default to building against Any CPU - if the DLL is specific to a bitrate (ie x86 or x64) then it might be that the program picks the wrong bitrate on end machines (usually x86) but the right one on your machine (x64). This is usually best resolved by building out different x86 and x64 versions; it's messier, but only .NET itself is good at using the Any CPU paradigm.
The exception should have detail about what DLL in particular was not found - maybe look closer?
GPSVC and IESHIMS missing should not be a problem; as indicated by the hour glass, they're deferred dependencies anyway.

Setting up 32feet library

I'm trying to get started with this library: 32feet
I have a Broadcomm Bluetooth Stack and haven't been able to figure out how to get this library set up. When I run my code, I get:
Unhandled Exception: System.PlatformNotSupportedException: No supported Bluetooth protocol stack found.
After digging around on their site, I found this: Installation instructions
It says to copy the appropriate DLL's into the project and then run the Test32FeetWidcommWin32.exe. I've tried putting the files in every single folder in my Visual Studio project and then running that EXE, but I still get the same error. Initially I tried just adding the InTheHand.Net.Personal.dll file as a reference to my project, but that didn't work either.
What could I be doing wrong?
It may also simply be that BlueTooth is not turned on in Windows.
I was using the .NET InTheHand library, and received this message only because BlueTooth was turned off in Windows, and resolved it by activating BlueTooth.
I just solved this. I think the problem was an old reference in my project to the NETCF version of the DLL from when I was trying to brute-force a solution, so I wiped my project clean and then started adding everything again and it worked!
A helpful tool to those trying to figure out their problem with this is to copy and paste the app.config file into your release directory with the app you are creating, and change the name to <YOUREXENAME>.exe.config. When you then run your EXE file, it should create a more detailed trace file. For mine, I found that coredll.dll was the culprit by not loading and was masked by the Stack not supported exception. After an easy Google search I found the problem to be with NETCF.
edit: To be clear, after I cleaned out my project a bit I re-added the reference to the correct InTheHand.Net.Personal.dll file and also added the 32feetWidcomm.dll file to my Release folder.

EmguCV 64-bit build runtime error

I am running into issues building an existing 32-bit EmguCV (Version 2.3) into 64-bit using .net 4.0 and VS2010 on a W7/x64 OS. I have purchased a commercial license, if that matters and downloaded from the links provided in the receipt.
The error is
System.TypeInitializationException was unhandled
Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
Source=Emgu.CV
TypeName=Emgu.CV.CvInvoke
I followed the instructions provided in this article. In fact I used the samples projects in the article and they build fine with V2.2, but when I replace with V2.3 binaries (both emgu and opencv), run into the error.
Has anyone successfully built an Emgu (Version 2.3.x) x64 project? Please provide some guidance.
The cause of this error (should anyone else run into the same problem) is that the program cannot access opencv_imgproc231.dll or opencv_core231.dll even though they are present in the output "bin" directory.
There are two solutions:
Add them to the project and set their properties to copy always as they are EMGU's two key files.
If step 1 doesn't work, replace the current key files in the bin folder with new copies.
If both methods fail then there may be a problem with the build, so download a new copy of EMGU from Sourceforge and try again. The error will later be incorporated within an technical article in order to provide a clearer explanation of how to solve it.
Cheers,
Chris
No need to add them to the project; VS will not let you. Simply open FaceRecognizer.cs
at public static partial class CvInvoke and change:
[DllImport(CvInvoke.EXTERN_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]
to:
[DllImport(Emgu.CV.CvInvoke.EXTERN_LIBRARY, CallingConvention = Emgu.CV.CvInvoke.CvCallingConvention)]
Ensure you change all of them.
First test this way: open a sample project from emgu cv installaiton directory and run it. for example, open hello world example and try to run it. if sample projects run with out problem then the installation is correct.
For emgu cv sample projects, value of Output Path option in Build settings of the project is set to '..\..\
bin'. To fix your project problem, open the project in visual studio and set value of Output Path option to 'C:\Emgu\emgucv 2.9\bin'. Try to run the project. It must run with success.
Now, set back the value of Output Path option to bin\Debug\. Then, add all DLL files in the 'C:\Emgu\emgucv 2.9\bin' folder to your project using ADD -> Existing Item menu. similarly, add all DLL files in the 'C:\Emgu\emgucv 2.9\bin\x64' folder to your project using ADD -> Existing Item menu. Now, go to properties window and set Copy to Output Directory option of all dll files to Copy Always. Finally, in the Configuration Manager window, create a new configuration for x64 platform.
Good Luck

unable to find an entry point named 'interlockedexchange'

I built an application in c# vs2005 .net .
Everything works fine when i run the application in win 32 bit, But
when running the application in win 64 it crashes while trying to call
the pinvoke interlockedexchange(which is within the kernel32.dll) function .
This is the exception :
unable to find an entry point named 'interlockedexchange'
I didnt find the interlockedexchange function within the kernel32.dll under system32 directory but it was found under the syswow64 directory(in the kernel32.dll) .
I guess that the .net runtime is configured to the system32 directory and not to the syswow64 .
How is it possible to change this configuration ? Can you think of any other problem that could cause this?
any help would be appreciated!
thanks ,
Miki Amit
If you are set on using InterlockedExchange and want the 32-bit version, you can change your project settings to force it to run as 32-bit. Go to the "Build" tab in the project settings and change "Platform target" to x86. It will then run as 32-bit.
This does not directly answer your question, but why not call System.Threading.Interlocked.Exhange() rather than resorting to P/Invoke?

Categories

Resources