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
Solved

DLLImport Not Working on Windows Server 2008 R2

Posted on 2012-03-27
10
1,812 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
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…

856 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