When a DLL is not found while P/Invoking, how can I get a message about the specific unmanaged DLL that is missing? - pinvoke

When you link to an unmanaged library (say 'A.dll') which in turn links to another library ('B.dll'), and B.dll is missing, you will get a run-time error message about failing to load 'B.dll'.
But when you P/Invoke into 'A.dll' from managed code, you'll get a general exception of this form:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'A.dll': The specified module could not be found.
How can I get an error message that pinpoints the specific unmanaged dll file that failed to load, when p/invoking from managed code ?

I don't think there's any specific API you can use to pinpoint why LoadLibrary (the underlying Win32 API) failed for 'A.dll'. I recommend the use of a tool like Dependency Walker to troubleshoot DLL loading errors.

I'm not sure how you can get this in the form of an exception. When I run into this problem I usually try and open the DLL with depends.exe. It's pretty good and reporting missing dependencies that exist if the DLL is simply loaded from it's current location.

You won't be able to get an answer from the exception, but you can do it (with a lot of work) through Process Monitor. This article discusses how and also includes a tool to scan Process Monitor logs to find the specific problem.
http://tech.blinemedical.com/debug-could-not-load-file-or-assembly-or-one-of-its-dependencies/

The Fusion Log Viewer is a good tool to debug assembly loading problems in .NET apps.
For identifying general file-load problems, you can use Process Monitor.

Related

Cannot find "stateless_validation.h" after calling CreateShaderModule() in Vulkan

I have tried to setup Vulkan validation layers, and after running vulkaninfoSDK.exe indeed have multiple validation layers, but I get a message in VS Code "unable to open 'stateless_validation.h': Unable to read file 'c:\j\msdk\build\vulkan-validationlayers\repo\layers\stateless_validation.h".
This message is very strange to me, as I do not even have a folder "j" on my c drive, and have in fact installed Vulkan somewhere on a completely different drive. I am running Windows, the MSVC compiler, have installed the latest Vulkan SDK from LunarG, and have set the environment variable "VK_LAYER_PATH" as recommended here: https://vulkan.lunarg.com/doc/view/1.2.131.1/windows/layer_configuration.html but indeed, the folder I have installed the SDK to does not contain a "stateless_validation.h".
My call stack is 3 functions in VkLayer_khronos_validation.dll: "StatelessValidation::validate_struct_pnext", then "StatelessValidation::PreCallValidateCreateShaderModule,", then "vulkan_layer_chassis::CreateShaderModule" called from my own function.
I notice the file "stateless_validation.h" is on the Github repo here: https://github.com/KhronosGroup/Vulkan-ValidationLayers but I would think downloading the SDK would be enough.
How can I solve this?
It seems that the error was an exception thrown inside the actual validation layer source code itself, and was due to the pNext member of my VkShaderModuleCreateInfo structure instance I was passing to vkCreateShaderModule being uninitialized.
Simply setting this to nullptr solved my issue. It seems that since the exception was thrown from inside the dll itself, my exception handling code was not catching it, which confused me.

How to load a dll in Tcl?

What I have tried (running Tcl and Tk 8.6.0 on Windows):
load D:/toot/bar/em.dll
load "D:/toot/bar/em.dll"
load D://toot//bar//em.dll
load "D://toot//bar//em.dll"
load D:\toot\bar\em.dll
load "D:\toot\bar\em.dll"
load D:\\toot\\bar\\em.dll
load "D:\\toot\\bar\\em.dll"
All of which return one of these two errors:
couldn't load library [what I put after 'load']: invalid argument
couldn't load library [what I put after 'load', rendered]: this library or a dependent library could not be found in library path
Assuming that file exists D:/toot/bar/em.dll returns truea, load D:/toot/bar/em.dll should work. However, it sounds like you've got problems with things (i.e., other DLLs) that the library depends on.
This is a general problem on Windows that has been asked elsewhere on Stack Overflow; the answers there are relevant to this question. You should also be aware that if the DLL has been linked against a specific version of the Tcl DLL (not recommended on Windows for Tcl extensions) then you need to have the same version of Tcl installed as it was linked against. Stub-enabled extensions do not have this problem at all (though they can still run into problems with other required libraries being absent).
It's a shame that the load command doesn't tell you what DLL is missing in its error message, but IIRC the underlying OS API doesn't report it either. You're stuck with using an external tool to diagnose these thingsā€¦
a Don't worry about backslash/forward-slash issues; Tcl handles those for you.
I have this problem, too,couldn't load library "ChariotExt": invalid argument.
And sovled it by change tcl version x64 to x86.

Reflexil deobfustication error

I'm trying to modify a .net application and I'm new to this. First step is attempting to deobfuscate the code using reflexil and I get the following error:
Reflexil is unable to clean this assembly: Member 'System.RuntimeTypeHandle "bunch of obfustatcated jibberish"(System.Int32)' is declared in another module and needs to be imported
The application comes with a bunch of dll's that it certainly uses, so I assume the declaration is in one of those files. How do I import this module?
In case it's helpful, reflexil says it was obfuscated with .NET Reactor 4.1
I decided to try de4not to deobfuscate and it worked without this issue.

JNI UnsatisfiedLinkError- how do I load libraries correctly?

I'm trying to work with the Java sample Database program from the CardScan SDK.
I am working with files located in Java/JNI and Java/Database. The program must be run with a 32 bit JRE. I was able to do so on a 64 bit machine by uninstalling Java and installing the 32 bit version, then re-adding the system path for Java. I can run the program and interface with a CardScan database file (.cdb) successfully by double clicking the SDKData.bat file, but when I open the source files for editing and edit the Java.library.path to include the required library (CRTK_JNI.dll), I get UnsatisfiedLinkErrors everywhere:
Exception in thread "main" java.lang.UnsatisfiedLinkError: sdkdata.CRTK.CRTK_Init([I)I
at sdkdata.CRTK.CRTK_Init(Native Method)
at sdkdata.CRTK.(CRTK.java:239)
at sdkdata.SDKData.(SDKData.java:97)
at sdkdata.SDKData.main(SDKData.java:643)
Java Result: 1
Presumably this is happening because the library is not loading properly.
What do I need to do to run and edit the program at full capacity (with all the native functions from CRTK_JNI in working order)?
Presumably this is happening because the library is not loading properly.
On the contrary. The library load is complete. You aren't getting that from a System.load()/loadLibrary() call, you are getting the error when calling your native method, the one that should have the signature:
package sdkdata;
public class CRTK
{
public native int CRTK_Init(int[]);
}
So it isn't there, or you have changed the signature without regenerating the .h and .c files, or you have manually mangled the declaration some other way.
Post your code.
To clarify, this Java sample program is officially unsupported by the CardScan API - it was a bad idea to try to use the API with an unsupported language relying solely on an experimental implementation. I ended up using one of the supported languages (Visual Basic) to work with the SDK; if anyone looking at this question happens to be struggling with using the CardScan API, here is my VB implementation on Github.

Team Build sends error when trying to compile a Structuremap method

I'm getting a strange error when trying to compile a solution that is using StructureMap on Team Build.
When I try to compile the solution locally on Visual Studio it works fine, but when trying to queue a new build in Team Build I get the following error:
Overload resolution failed because no accessible 'Use' can be called with these arguments:
The line of code that gets this error is the second one:
ForSingletonOf(Of ISessionFactory)().Use(NHibernateSessionFactory.SessionFactory)
Me.For(Of ISession)().lifecycleIs(New HybridLifecycle()).Use(Function(x) x.GetInstance(Of ISessionFactory)().OpenSession())
It's a standard registration for the NHibernate session, so I don't really get why this error pops up.
Thanks in advance for the clues.
Make sure you have the correct version of NHibernate on the build server, and that your hint paths are all appropriately set in your project file. We haven't had this specific issue (as we're not using NHibernate), but we've had weird issues like that being related to version mismatches of "infrastructure" DLLs between local and build.