简体   繁体   中英

How to add a reference to 32 bit dll in ASP.NET application

I try to add a reference to 32 bit dll in ASP.NET application with IIS Express.

But there's a problem. When I start the app, it throws the exception:

'Could not load file or assembly 'CppInerop.dll' or one of its dependencies. The specified module could not be found.'

I've tried to set the target platform to x86 and x64 but nothing changed.

This dll works good with console and win forms apps. I've just changed the property target of those ones from any CPU to x86 .

But it still doesn't work with ASP.NET. I saw some other options, added all required dll to bin of course. But nothing can change the result.

This dll was written on C++ .

Additionally I used fuslogvw , but it doesn't log anything about this dll.

Please help to see, why does it happen.

You can't easily do this.

You're probably going to have to arrange to call the DLL out-of-process. I've accomplished such tasks that way.

This should work for web requests:

1) Make an .EXE that provides a suitable binary interface to call the DLL over stdin/stdout. The EXE deserializes arguments, calls DLL functions, serializes the result and sends it to stdout. You might be thinking wait what the API is too hard. Well I've not seen an API too hard for this yet. I got TWAIN scanning working this way.

2) Install .EXE and .DLL in another directory. Find a way for your webapp to locate it (posiably relative path or parameter in web.config)

3) Implement the other side of the binary interface in your web app. Start the process, serialize request, send request to the process's stdin, read the result from the process's stdout.

For VS2015 (and 2013) You can choose to run IIS Express in 32-bit or 64-bit by going in Visual Studio to:

Tools -> Options -> Projects and Solutions -> Web Projects 
check/uncheck "Use the 64 bit version of IIS Express for web sites and projects"

For your case you want this option to be unchecked

Also, in your web project make sure you are also targeting the x86 platform in your build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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