Unmanaged DLL: DllNotFoundException on certain platforms

Last post 05-30-2008 1:33 PM by ncod. 6 replies.

Sort Posts:

  • Unmanaged DLL: DllNotFoundException on certain platforms

    05-28-2008, 9:14 PM
    • Member
      point Member
    • ncod
    • Member since 05-28-2008, 9:09 PM
    • Posts 5
    I wrote a win32 DLL to do some custom data storage for a project. I then used DllImport to access the functions in this DLL from my asp.net pages.
    This works perfectly on my test setup of Windows XP Pro SP2 using Visual Web Developer Express 2008's builtin development server. It also works correctly using IIS 5 with .net framework 3.5 installed.

    However, when I move the code to a Windows 2003 Server Enterprise Server, which runs IIS 6 (also with .net framework 3.5), the dll function call throws an exception:

    System.DllNotFoundException: Unable to load DLL 'DataAPI.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at DataAPIDLL.CloseNewStorage(Int32 iStorageID) at TestDLL.Page_Load(Object sender, EventArgs e) in e:\webroot\TestDLL.aspx.cs:line 27

    DataAPI.dll is currently in the bin directory of my site. Here is a sample code-behind file of a page that I am using to do this test:

    using System;
    using System.Runtime.InteropServices;
    
    public class DataAPIDLL {
    
    	[DllImport("DataAPI.dll")]
    	public static extern void CloseNewStorage(int iStorageID);
    }
    
    public partial class TestDLL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    		try {
    			DataAPIDLL.CloseNewStorage(-1);
    		} catch (Exception ex) {
    			lblResult.Text = ex.ToString();
    		}
        }
    }
    

    It seems to make no difference if I specify an entrypoint or charset in the dllimport statement. It works on the development machine's dev-server and IIS but not on the win2k3 machine. There were also some short periods of time (minutes) where it did not work on the development server for no apparent reason. That problem seemed to fix itself.

    Any suggestions. I've been screwing around with this for almost 2 full days and have gotten nowhere. The passive internet usually has answers to these obscure technical problems, but not this time. I have tried a few other things, but don't want to list them since they might dissuade suggestions. Thanks.

    If you think I could learn something useful from it, I could install and try the visual webdev development server on the win2k3server system and see how that behaves.
  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-28-2008, 9:33 PM
    • All-Star
      33,841 point All-Star
    • vcsjones
    • Member since 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 4,319
    • Moderator
      TrustedFriends-MVPs

     Seems simple enough, does the DataAPI.DLL file actually exist on the Windows 2003 server? (Are you sure that it has been copied?)

    Also, is it in the same path that the .NET Framework is expecting it to be?

    If you provide no path, the DLL must be in the current path at run time

    What happens if you do specify a fully qualified path? i.e. C:\somedirectory\DataAPI.DLL.

    Cheers,
           Kevin Jones


  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-28-2008, 10:57 PM
    • Member
      point Member
    • ncod
    • Member since 05-28-2008, 9:09 PM
    • Posts 5
    Thanks for the quick reply but still no luck.

    I had placed the DLL in my site's bin directory. That is where it seems to work on my xp machine with IIS and development server. I did try to specify an absolute path, but the Exception was the same.

    I used filemon and watched the file access in action when making a request for the test page in question. The w3wp process does hit DataAPI.dll with a few repetitions of 'query information', 'open', 'read'; all of which produce result 'success'. I'm not really familiar with filemon, so i'm not sure what to make of this information. Nothing in the 'Other' column looks suspicious. The value is either 'Attributes: A', 'Options: Open Access: 00100020', 'Length:98304'. The other rows are similar but with different open information.

    This seems to be contrary to the DllNotFoundException I see, since it clearly IS found. Does that mean that the problem is with loading the DLL? Why on win2k3 but not xp then?
  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-28-2008, 11:15 PM
    • All-Star
      33,841 point All-Star
    • vcsjones
    • Member since 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 4,319
    • Moderator
      TrustedFriends-MVPs

    Is your Windows 2003 Server 64-bit? Does the DLL have the correct NTFS permissions? 

    Cheers,
           Kevin Jones


  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-28-2008, 11:42 PM
    • Member
      point Member
    • ncod
    • Member since 05-28-2008, 9:09 PM
    • Posts 5
    It is 32. I actually tried running the dll at one point in IIS 6 on a xp64 machine and it was a different exception that reflected the 32/64 conflict.

    Can you clarify your statement about permissions. The Users group already has Read & Execute permissions. All of the relevant users (aspnet, network serices) who might try to access the dll are in the users group.
  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-30-2008, 12:11 PM
    • Member
      point Member
    • ncod
    • Member since 05-28-2008, 9:09 PM
    • Posts 5
    bump.
    Anyone have any insight?
  • Re: Unmanaged DLL: DllNotFoundException on certain platforms

    05-30-2008, 1:33 PM
    Answer
    • Member
      point Member
    • ncod
    • Member since 05-28-2008, 9:09 PM
    • Posts 5
    Solved it. It was missing a dll dependancy that was on other systems but not this one.

    That it was saying the DLL was not found instead of that it could not be loaded is absurd. Thanks.
Page 1 of 1 (7 items)