Search code examples
c#wcfiispinvoke

WCF PInvoke produces "Access is denied"


I have a WCF implementing REST interface using webHttpEndpoint endpoint.

Call stack is something like this: WCF Service >> C# Library >> PInvoke >> C++ Library

When run from Visual studio everything works as expected. When deployed to IIS the following error happens:

System.DllNotFoundException: Unable to load DLL 'native.dll': Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at ...

All the .dll files are in \bin folder.

Exactly the same C# Library/PInvoke chain works in a Web Forms ASP.NET site on the same server.

Here is the web.config for WCF service:

 <system.web>
   <trust level="Full"/>
   <compilation debug="true" targetFramework="4.0" />
   <customErrors mode="Off"/>
 </system.web>

 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </modules>
 </system.webServer>

 <system.serviceModel>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
   <standardEndpoints>
     <webHttpEndpoint>
       <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
     </webHttpEndpoint>
   </standardEndpoints>
</system.serviceModel>

Is there something special in WCF environment or are there specific permissions required for the native dll to be found/accessed ?

Additional Info Removing native.dll from /bin produces:

System.DllNotFoundException: Unable to load DLL 'util32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

So it's actually finding the file.


Solution

  • Turns out this is a result of a simple permission issue on the file.