Asp.Net C# DllImport 问题
我想在我的网站项目中导入 DLL 文件。我在文件夹 C:\DLLDir 中有 dll 文件“my.dll”,我正在使用代码:
[DllImport("C:\\DLLDir\\my.dll", EntryPoint = "Out32")]
这工作正常。但我想使用相对路径(网站根路径)。我试图将“my.dll”放入“bin”或根文件夹中,并且我正在使用代码:
[DllImport("my.dll", EntryPoint = "Out32")]
但我收到错误:无法加载 DLL 'my.dll':指定的模块无法成立。 (HRESULT 异常:0x8007007E)
有什么想法吗?
I want to import DLL file in my web site project. I have dll file "my.dll" in folder C:\DLLDir and I'm using the code :
[DllImport("C:\\DLLDir\\my.dll", EntryPoint = "Out32")]
This works ok. But I want to use relative path (web site root path) . I'm trying to put "my.dll" in "bin" or root folder and I'm using the code :
[DllImport("my.dll", EntryPoint = "Out32")]
but I'm getting the error: Unable to load DLL 'my.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想你可能想先检查以下问题(因为它与你的情况有关):
DllImport 无法找到 DLL,即使它在 PATH 中
正如其他人所建议的,检查
PATH
环境变量以使确保C:\DLLDir\
在那里。您可以在此处了解有关如何配置环境变量的更多信息。查看此 MSDN 论坛也发布(似乎依赖项存在问题)。
如果您要导入的是 COM DLL,那么它可能还需要首先在目标计算机上注册(尽管我不确定是否需要这样做)。 在此处了解更多信息。
I think you may want to check out the following SO question first (since it's related to your case):
DllImport failed to locate DLL even though it is in the PATH
As other people has suggested, check the
PATH
environment variable to make sure thatC:\DLLDir\
is there. You can read more about how to do configure your environment variables here.Check out this MSDN forum post as well (seems like there was an issue with dependencies).
If it's a COM DLL you're importing then it might also requires to be registered first on a target machine (although I'm not sure if this is needed). Read more here.
您没有将 my.dll 复制到应加载它的 Bin 文件夹中。
使用 Process Explorer ( http://technet.microsoft.com/en-us/sysinternals /bb896653.aspx) 将显示它尝试从何处加载此文件。
编辑:感谢 volpav 提醒它是非托管 DLL - 忽略托管部分...
...程序集还有一些其他依赖项。
查看 http://blogs.msdn.com/b /suzcook/archive/2003/05/29/57120.aspx 详细说明了此类故障的调查(搜索“程序集加载融合日志”以获取更多链接)。
Either you did not copy my.dll to Bin folder where it should be loaded.
Using Process Explorer ( http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) will likley show where it tries to load this file from.
EDIT: thanks to volpav for reminding that it is unmanaged DLL - ignore manged portion...
...assembly have some other dependencies.
Check out http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx that details investiagtion of such failures (search for "assembly load fussion log" for more links).
转到
Properties/Build
选项卡,并将 Platform target 设置为x86
。Go to
Properties/Build
tab, and set Platform target tox86
.我相信 DLL 必须位于您的路径上(如果不是绝对路径)。可能会让您感到惊讶的是,除非您特别添加“.”,否则 CWD 并不在您的路径上。在你的 PATH 变量中。
I believe the DLL has to be on your path (if not absolute). And what will likely surprize you is that CWD is not on your path unless you specifically add "." in your PATH variable.