Solved

DLLImport Not Working on Windows Server 2008 R2

Posted on 2012-03-27
10
1,857 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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