无法从ASP.NET调用DLL [英] Unable to call the DLL from ASP.NET

查看:179
本文介绍了无法从ASP.NET调用DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C Dll,它将与cobol应用程序进行交互。我们想通过互联网将数据发送到cobol。



所以我创建了一个C#DLL,它将调用C DLL。当我做一个consoleapp时,它的工作正常,但是当我尝试从ASP.NET调用相同的DLL时,它给出错误消息



我不明白错误

 尝试加载格式不正确的程序。 (来自HRESULT的例外:0x8007000B)

还有一些其他帖子,但这些不符合我的上下文
i认为缺少权限为asp.net



这是我的c#dll中的声明调用c dll

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



编辑:



设置根据您的建议,但现在得到一个新的错误

  Microsoft Visual Studio C运行时库已检测到w3wp中的致命错误。 exe 


解决方案

如果你有一个C .dll,将是32位或64位。您必须确保您的网站正在正确的平台上运行(即,您的网站正在以匹配的32/64位网站运行。)



IIS 7,您可以通过右键单击应用程序池并选择高级设置来配置应用程序池的位。有一个名为的设置启用32位应用程序,您需要将其设置为32位站点的 True code> False 为64位网站。



您可以使用 Dependency Walker 查看DLL是否为32位或64位:使用查看完整路径(看起来像 C:\ 在工具栏上),如果您的.dll依赖关系:




  • 如果你有一个32位操作系统,你的.dll可能是64位。您将无法加载它。

  • 如果您有一个64位操作系统:


    • 如果依赖关系在System32下,它是一个64位的.dll

    • 如果依赖关系在SysWOW64下,它是一个32位的.dll

    / li>


这将告诉您如何设置应用程序池。要设置应用程序池,您可以检查此链接



确保使用高级设置打开应用程序池属性,而不是基本设置。此外,当您为网站启动属性时,这些设置不可用 - 它们仅适用于应用程序池。


Hi I have a C Dll which will interact with a cobol application. we want to send the data to the cobol through internet.

so i created an C# DLL which will call the 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

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

this is the declaration in my c# dll for calling 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. 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.)

In IIS 7, you can configure the bitness of the application pool by right-clicking the app pool and selecting 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.

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:

  • If you have a 32-bit OS, your .dll may be 64-bit. You won't be able to load it.
  • If you have a 64-bit OS:
    • If the dependencies are under System32, it's a 64-bit .dll
    • If the dependencies are under SysWOW64, it's a 32-bit .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. Also, these settings are not available when you bring up properties for your site - they are only available for the app pool.

这篇关于无法从ASP.NET调用DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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