Solved

DLLImport Not Working on Windows Server 2008 R2

Posted on 2012-03-27
10
1,748 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now