Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:32:50+00:00 2026-05-15T14:32:50+00:00

I’m having an issue when calling 32 bit Delphi DLL files from a C#

  • 0

I’m having an issue when calling 32 bit Delphi DLL files from a C# web site. The code generally runs fine, but occasionally I get an error,

*Unable to load DLL ”: The specified module could not be found. (Exception from HRESULT: 0x8007007E).

This issue persists until I recycle the application pool for the site, and then it works fine again.

On the same server, there is also a web service that is calling the same set of DLL files. This web service doesn’t seem to have the same issue that the web site has.

Both applications are using .NET Framework 3.5, separate application pools on IIS.

Here is the code I’m using to wrap the DLL files:

public sealed  class Mapper
{
    static Mapper instance = null;

    [DllImport("kernel32.dll")]
    private static extern bool SetDllDirectory(string lpPathName);

    private Mapper()
    {
        SetDllDirectory(ConfigManager.Path);
    }

    public static Mapper Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Mapper();
            }
            return instance;
        }
    }

    public int Foo(string bar, ref double val)
    {
        return Loader.Foo(bar, ref val);
    }
}


public static class Loader
{
    [DllImport("some.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, EntryPoint = "foo")]
    public static extern int Foo(string bar, ref double val);
}

Then I call it like this:

double val = 0.0; 
Mapper.Instance.Foo("bar", ref val);

Why would it “randomly” Unable to load DLL ”: The specified module could not be found. (Exception from HRESULT: 0x8007007E).?

The other problem is that I haven’t been able to replicate the issue in the development environment. I thought that due to two applications calling the same DLL files, that there could be some locks occurring. To replicate this, I created an application that spawned multiple threads and repeatedly called the 32-bit DLL files, and then used the web site to call these same DLL files. I still couldn’t replicate the issue.

Some possible fixes that I can think of:

  1. Wrap the 32 bit DLL files in the web service (because the web service doesn’t seem to suffer from the same problem). But this may be worthless if it turns out that the web service also fails.
  2. Set up state server for the session state and periodically recycle the application pool for the site.This isn’t fixing the problem, only avoiding it.
  3. Wrap the DLL files in an EXE file, and call that EXE file. Then I shouldn’t get the same issue. But this also seems like a hacky solution.
  4. Implement the mapper class differently? But how else should I be doing the call? The other drawback is that other applications are using this mapper, so I’d need to change there code too.

What should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:32:50+00:00Added an answer on May 15, 2026 at 2:32 pm

    To fix this issue (it’s stopped happening now), I left the mapper code as is, but in the calling application I manually set the path (even though the mapper DLL file does it most of the time).

    So in the main application, I make a call to append the path of the directory where the DLL files are located.

    private static void AddEnvironmentPaths(string[] paths)
    {
        string path = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
        path += ";" + string.Join(";", paths);
    
        Environment.SetEnvironmentVariable("PATH", path);
    }
    

    What’s strange is that the mapper class works most of the time, but sometimes stopped. Adding the path with the above code seems to have solved the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 435k
  • Answers 435k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because you should be showing the count, not iterating over… May 15, 2026 at 3:40 pm
  • Editorial Team
    Editorial Team added an answer Don't just use XML because it's XML. Use XML because:… May 15, 2026 at 3:40 pm
  • Editorial Team
    Editorial Team added an answer Calling std::vector<>::clear() does not necessarily free all allocated memory (it… May 15, 2026 at 3:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.