P /在ASP.NET中调用(找不到Dll异常) [英] P/Invoke in ASP.NET (Dll not found exception)

查看:84
本文介绍了P /在ASP.NET中调用(找不到Dll异常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过C ++项目生成的.dll。我必须在我的ASP.NET项目中使用该dll,并且在我的项目中为此编写了DllImport函数。

I have a .dll that I generated thorugh a C++ project. I have to use this dll in my ASP.NET project and I have written DllImport functions for the same in my project.

中的静态类App_Code 具有一些 DllImport 函数

public static class Functions
{
    [DllImport("MyFav.dll", EntryPoint = "fnmain", 
     CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern StringBuilder fnmain();
}

由于我无法将C ++ dll直接添加为ASP中的引用。 NET项目(因为它不是.NET程序集),所以我只是将其复制到顶层目录中。 (ASP.NET项目的名称->右键单击->添加现有项)

Since I could not add the C++ dll directly as a reference in my ASP.NET project (because it is not a .NET assembly), I just copied into the top level directory. ( Name of ASP.NET Project-> Right Click -> Add Existing Item )

现在,当我尝试运行该项目时,出现以下错误:

Now, when I try to run the project, I get the following error:

例外:


无法加载DLL'MyFav.dll':指定的模块找不到。 (来自HRESULT的异常:0x8007007E)

Unable to load DLL 'MyFav.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

有什么建议吗? .dll存放在哪里?

Any suggestions? Where has the .dll to be kept?

推荐答案

.dll 应该位于asp.net应用程序的 \bin 文件夹中。

The .dll should be in the \bin folder of your asp.net application.

显然,dll的使用规则解决了。请参见 msdn上的动态链接库搜索顺序

Apparently there are rules for how dlls are resolved. See Dynamic-Link Library Search Order on msdn

您也可以尝试:

[DllImport("C:\path_to_dll\MyFav.dll", EntryPoint = "fnmain", 
 CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern StringBuilder fnmain();

如果这一切都不起作用,也许您的 MyFav.dll 还有其他未解决的依赖关系。您可以使用 Dependency Walker 进行检查。

If all this doesn't work, maybe your MyFav.dll has additional unresolved dependencies. You could use Dependency Walker to check for these.

这篇关于P /在ASP.NET中调用(找不到Dll异常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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