简体   繁体   English

无法从ASP.NET调用DLL

[英]Unable to call the DLL from ASP.NET

Hi I have a C Dll which will interact with a cobol application. 嗨,我有一个C dll,它将与cobol应用程序进行交互。 we want to send the data to the cobol through internet. 我们想通过互联网将数据发送到cobol。

so i created an C# DLL which will call the C DLL. 所以我创建了一个C#DLL,它将调用C DLL。 its working fine when i do a consoleapp, but when i try to call the same DLL from ASP.NET its giving error message 当我做一个consoleapp时,它的工作正常,但是当我尝试从ASP.NET调用相同的DLL时,它给出错误消息

i dont understand that error 我不明白这个错误

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

There are some other posts regarding this but those were not matching my context i think im missing permissions for asp.net 还有其他一些相关的帖子,但那些不符合我的上下文我认为我缺少asp.net的permissions

this is the declaration in my c# dll for calling c dll 这是我的c#dll中用于调用c dll的声明

[DllImport(@"C:\CCExpert\haz450cp.dll", EntryPoint = "Methodname", CallingConvention = CallingConvention.Cdecl)]
    unsafe public static extern void Methodname(ref p1, ref p2);

Edit: 编辑:

Hi i changed the settings according to your suggestions but now im getting a new error 嗨我根据你的建议改变了设置,但现在我得到一个新的错误

Microsoft Visual Studio C Runtime Library has detected a fatal error in w3wp.exe

If you have a C .dll, it'll be either 32-bit or 64-bit. 如果你有一个C .dll,它将是32位或64位。 You must make sure that your site is running in the correct platform for that (that is, your site is running as a matching 32/64-bit site.) 您必须确保您的站点在正确的平台上运行(即,您的站点作为匹配的32/64位站点运行。)

In IIS 7, you can configure the bitness of the application pool by right-clicking the app pool and selecting Advanced Settings . 在IIS 7中,您可以通过右键单击应用程序池并选择“ Advanced Settings来配置应用程序池的位数。 There's a setting called Enable 32-bit applications , you need to set that to True for 32-bit sites and False for 64-bit sites. 有一个名为Enable 32-bit applications设置,你需要为32位站点设置为True ,为64位站点设置为False

You can use Dependency Walker to see if the DLL is 32-bit or 64-bit: use View full paths (looks like C:\\ on the toolbar) and if the dependencies of your .dll and: 您可以使用Dependency Walker查看DLL是32位还是64位:使用View full paths (在工具栏上看起来像C:\\ )以及.dll的依赖项和:

  • If you have a 32-bit OS, your .dll may be 64-bit. 如果你有32位操作系统,你的.dll可能是64位。 You won't be able to load it. 你将无法加载它。
  • If you have a 64-bit OS: 如果您有64位操作系统:
    • If the dependencies are under System32, it's a 64-bit .dll 如果依赖项在System32下,则它是64位.dll
    • If the dependencies are under SysWOW64, it's a 32-bit .dll 如果依赖项在SysWOW64下,则它是32位.dll

That tells you how to set the application pool. 这告诉您如何设置应用程序池。 To set the app pool you can check this link . 要设置应用程序池,您可以查看此链接

Make sure you use Advanced Settings when you open the app pool properties, not basic settings. 确保在打开应用程序池属性时使用“ Advanced Settings ,而不是基本设置。 Also, these settings are not available when you bring up properties for your site - they are only available for the app pool. 此外,当您为站点启用属性时,这些设置不可用 - 它们仅适用于应用程序池。

The most likely cause of this problem is that you are trying to load a 32 bit DLL into a 64 bit process (or vice versa). 导致此问题的最可能原因是您尝试将32位DLL加载到64位进程(反之亦然)。 To verify or rule this out check and see if the Asp.Net is running in 64 bit mode and if so you need to have a 64 bit version of the C DLL 要验证或排除此问题,请检查Asp.Net是否以64位模式运行,如果是,则需要64位版本的C DLL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM