Calling an unmanaged DLL from a web service.

Discussion in 'ASP .Net Web Services' started by Chris Bardon, Jun 14, 2004.

  1. Chris Bardon

    Chris Bardon Guest

    I have some code in an unmanaged DLL that I want to call from a web
    service. What I've done is use DLLIMPORT statements to create a
    wrapper class like so:

    public class Import
    [DllImport("unmanaged.dll")] public static extern short Fn1(short

    And called it like so:


    I've placed the unmanaged.dll file in the path, and have used this
    code in a local windows forms app with no problems. When I try to
    place this same code in a web service though, I get a
    System.DLLNotFoundException saying that it is unable to load the
    managed DLL. I've tried placing copies of the DLL in various
    locations (web service bin directory, wwwroot, etc) with no

    Thinking it might be a security problem, I tried running my windows
    forms app as a different user, and confirmed that both the anonymous
    web service user and the ASPNET account were able to run the program
    and find the DLL. Is there another configuration issue here that I'm
    missing? There should be no reason that I can't use this DLL in this
    way, correct?
    Chris Bardon, Jun 14, 2004
    1. Advertisements

  2. Chris Bardon

    Daryl Davis Guest

    This appears to be a simular issue to mine. Works great except when I call
    it from a WebService.
    Daryl Davis
    Daryl Davis, Jun 14, 2004
    1. Advertisements

  3. Chris:

    Two suggestions from out of the blue.

    Have you tried using identity impersonation in web.config? Perhaps you
    could then use the %PATH% of the impersonated user for the dll location?


    This may or may not work. DLLImport states it takes a dll name in the
    constructor. Can the DLL name be a full path? I've never tried it
    before, but...

    As a test, place the dll in a known location (C:\unmanaged.dll).
    Does [DllImport("c:\unmanaged.dll")] work?

    Just some SWAGs.

    Jeff Clausius

    (Chris Bardon) wrote in
    Jeff Clausius, Jun 15, 2004
  4. Chris Bardon

    Russ Guest

    I think Jeff is on the right track here. I ran into the same thing.
    It seems that the Web Service will not look into it's own bin folder
    for the unmanaged dll. Why, I don't know. Anyway I 'solved' the
    problem by putting the unmanaged DLL in the %system32% directory.

    Of course the pain of that is well known...

    Good Luck, Russ

    Russ, Jul 2, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.