I’m having some difficulties while trying to consume an unmanaged-code dll
from my application (written in C# framework 4.0).
I’m using the dll
imp
Well, this was a very tricky problem. It was not related to dll dependencies and not related to the dll location either. It was not about how I was calling the DllImport
. It was a permissions problem.
Basically this issue is solved by taking out and then adding back the permissions for execute on the folder where the dlls are. See this article (Wayback machine).
Solution
Oracle 9.2 Client software requires that you give the Authenticated User privilege to the Oracle Home by following these steps:
Log on to Windows as a user with Administrator privileges.
Launch Windows Explorer from the Start Menu and and navigate to the
ORACLE_HOME
folder. This is typically the "Ora92" folder under the "Oracle" folder (i.e.D:\Oracle\Ora92
).Right-click on the ORACLE_HOME folder and choose the "Properties" option from the drop down list. A "Properties" window should appear.
Click on the "Security" tab of the "Properties" window.
Click on "Authenticated Users" item in the "Name" list (on Windows XP the "Name" list is called "Group or user names").
Uncheck the "Read and Execute" box in the "Permissions" list under the "Allow" column (on Windows XP the "Permissions" list is called "Permissions for Authenticated Users").
Re-check the "Read and Execute" box under the "Allow" column (this is the box you just unchecked).
Click the "Advanced" button and in the "Permission Entries" list make sure you see the "Authenticated Users" listed there with:
Permission = Read & Execute Apply To = This folder, subfolders and files
If this is NOT the case, edit that line and make sure the "Apply onto" drop-down box is set to "This folder, subfolders and files". This should already be set properly but it is important that you verify this.
Click the "Ok" button until you close out all of the security properties windows. The cursor may present the hour glass for a few seconds as it applies the permissions you just changed to all subfolders and files.
Reboot your computer to assure that these changes have taken effect (IMPORTANT).
Re-execute the application and it should now work.