的DllImport产生System.DllNotFoundException [英] DllImport generates System.DllNotFoundException

查看:918
本文介绍了的DllImport产生System.DllNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用来自我的应用程序的非托管代码 DLL 一些困难(用C#编写框架4.0)。
我使用了 DLL 进口如下:

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 import as follows

[DllImport(@"C:\MGW_SDK.dll", EntryPoint = "fInicializaSDK")]
public static extern int fInicializaSDK();



奇怪的是,从我的开发环境(Windows XP)呼吁,当它工作得很好,但当生产服务器(Windows7的),它会生成以下异常的:

The weird thing is that when called from my development environment (Windows XP) it works just fine, but when on the production server (Windows7) it generates the following exception:

System.DllNotFoundException :无法加载DLL 'C:\MGW_SDK.dll :指定的模块找不到。 (异常来自HRESULT:0x8007007E)在 Comtpaq.AdminPack.SDKWrapper.fInicializaSDK() Comtpaq.AdminPack.AdminPaqRepository.InitializeSDK() C:\Work\AgroIn\AdminPaqRepository.cs :行30

System.DllNotFoundException: Unable to load DLL ' C:\MGW_SDK.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Comtpaq.AdminPack.SDKWrapper.fInicializaSDK() at Comtpaq.AdminPack.AdminPaqRepository.InitializeSDK() in C:\Work\AgroIn\AdminPaqRepository.cs:line 30

我已经跑了的Dependency Walker ,这显示了以下依赖的冲突: C:\windows\system32\SHLWAPI.DLL

I already ran Dependency Walker, which shows the following dependency as conflicted: C:\windows\system32\SHLWAPI.DLL

我已经尝试过将其复制 DLL 我的部署目录

I already tried copying that dll to my deployment directory

MGW_SDK.dll C:\ (作为路径说)

我已经安装了C运行时库

I already installed C Runtime Library

我也注意到一些有趣的东西:外上,发展路径显示 C:\Work\AgroIn\AdminPaqRepository.cs:行30

I also noticed some interesting stuff: on the exception, the development path is showing C:\Work\AgroIn\AdminPaqRepository.cs:line 30

还有什么可能是这里的问题?

What else could be the problem here?

我建的的extern / dllimport的,我从<$ C使用方法只是一个小型控制台应用程序$ C> MGW_SDK.dll 并没有问题(没有 DllNotFoundException 凡)跑了,所以这似乎与我'应用M楼(WCF服务)。该服务托管在WAS,但我仍然无法找到的问题。

I built a small console application with just one of the extern/dllimport methods that I use from MGW_SDK.dll and ran it with no problem (no DllNotFoundException whatsoever), so this seems to be related to the application that I'm building (a WCF Service). This service is hosted on the WAS, but I'm still unable to find the issue.

推荐答案

好吧,这是一个非常棘手的问题。这是不相关的DLL依赖和不相关的DLL的位置无论是。这是不是我是如何调用的DllImport 。这是一个权限问题。

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.

基本上这个问题是由取出来,然后加回的权限所在的DLL是在文件夹上执行解决。请参见本文(Wayback机器)。

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).

甲骨文9.2客户端软件,您需要按照以下步骤给经过身份验证的
的用户权限Oracle主:

Solution


Oracle 9.2 Client software requires that you give the Authenticated User privilege to the Oracle Home by following these steps:


  1. 登录到Windows具有管理员权限的用户。

  1. Log on to Windows as a user with Administrator privileges.

启动Windows资源管理器从开始菜单,然后导航到 ORACLE_HOME 文件夹中。这是典型的甲骨文文件夹下的Ora92文件夹(即 D:\Oracle\Ora92 )。

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).

在ORACLE_HOME文件夹右键单击,然后从下拉列表中选择属性选项。应该出现一个属性窗口。

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.

在名称列表中点击验证用户项(在Windows XP中的名称列表被称为组或用户名称)。

Click on "Authenticated Users" item in the "Name" list (on Windows XP the "Name" list is called "Group or user names").

取消选中读取和运行,在允许一栏下的权限列表框中(在Windows XP中的权限列表被称为权限验证用户)。

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.

这篇关于的DllImport产生System.DllNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆