Solved

DLLImport Not Working on Windows Server 2008 R2

Posted on 2012-03-27
10
1,793 Views
Last Modified: 2012-06-08
I have a C++ DLL that I am attempting to use through a business class object and a DLLImport statement.  When I run the code locally on my Windows 7 Pro 64-Bit computer, everything works fine.  However when I run the exact same code on my production Windows 2008 R2 SP1 server, I get 400 Bad Requests returned to me.  I ended up using a debug tool and determined that IIS out in production is never calling this DLL and thus the errors must be to do with the DLLImport statement not retrieving the DLL.

I never registered the DLL on either my Windows 7 or Server 2008 box and, to be honest, I am using DLLimport statements because I am unable to directly reference the DLL in VS 2010.  I have run other DLLs in Production using DLLImport statements without any issue and I cannot figure out why this one is not working.

Any ideas?
0
Comment
Question by:ktola
  • 6
  • 4
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37773468
What type of project are you working with (WCF, REST Service, ...)?

Is this a COM DLL?
0
 

Author Comment

by:ktola
ID: 37773547
The DLL is not COM - it is a non-CLR C++ DLL thus the reason for the DLLImport

The code calling it is a WCF service using RESTful calls and JSON but none of that is the issue.  I can run everything locally with no issues
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37774791
Since this a REST service, all errors on the server side are translated to 400 Bad Request, so you need to log the exception on the server side to get the details.  

You need that information in order to find the reason for the failure.  My guess is that it can't find the library from the DllImport attribute, or you don't have access rights to the file.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:ktola
ID: 37774804
Unfortunately, I cannot trap the error as a DLLImport is an unmanaged call.  I tried adding the directory holding the DLL to the PATH; adding the DLL to the System32/SysWow64 directories and the InetSrv within each.  Nothing is working and I do not think the DLL is ever being called.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37775979
Unmanaged calls should still get an exception.  Are you catching the exceptions from the web service calls?  I have a WCF REST service where I log all calls, and all exceptions.
0
 

Author Comment

by:ktola
ID: 37777547
.NET only traps managed exceptions - things like DLLImport calls are not managed and cannot be trapped (I tried).  Worse yet nothing appears in the logs even though exceptions have to be thrown somewhere.  I know the issue is the fact that the DLL is not being called or accessed as it emits debug statements and the debug viewer for that DLL never activates when going through IIS.  If I run a console application on the server, the DLL works just fine and emits debug statements accordingly.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 37805845
Does the callee support GetLastError?

GetLastError and managed code
http://blogs.msdn.com/b/adam_nathan/archive/2003/04/25/56643.aspx
0
 

Author Comment

by:ktola
ID: 37824328
That is not the issue - we now have an open Microsoft support ticket and, thus far, they have failed as well to figure out the issue.  The DLL is being found, there are no extraneous references, and yet the DLL is not being called in Production.  Local IIS works just fine.
0
 

Author Comment

by:ktola
ID: 38062186
I wanted to provide the solution in case anybody else has this use.  As it turns out, Application Pools in IIS run under there own Application Pool Identities.  If you are referencing any third party or external DLLs, you need to provide specific permission to this identity in order to get things to work.  Here is a link - http://learn.iis.net/page.aspx/624/application-pool-identities/
0
 

Author Closing Comment

by:ktola
ID: 38062190
I appreciated your attempts to help...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question