0
votes

I have a c# mvc application which uses a c++ dll for some of the heavier statistical computation. Everything works fine when I run it locally but on my deployed application all I get is

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

The c# model is using

    [DllImport("HandCalculatorDll.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern bool CalculateWinner(int[] req);
    public RoundResult CalculateWinnerDll(List<Hand> hands, List<Card> board)
    {
        // set up the request
        // calls the dll
        var success = CalculateWinner(reqArr);
        // interpret the response
        return result;
    }

I've tried several different things but nothing seems to work for a deployed project. I tried both adding the dll to the project and removing it from the project (based on different recommendations). I tried several variations of relative and absolute paths. I used

    System.Web.Hosting.HostingEnvironment.MapPath("/bin");

to find the abolute path on the hosting pc, placed the dll in that bin folder, and used that path as the DllImport attribute.

Unfortunately, most of the recommendations/solutions I've found only work for local debugging. Does anyone know how to fix this?

UPDATE I copied the entire project onto a second computer to run it and that computer is throwing the same "Unable to load DLL" error that occurs when I publish. I'm running everything the exact same way on the second computer as on my home computer and I verified that the file is there. Now I'm really confused...

1
Just making sure: have you included that DLL in your VS project? And if so, have you set its properties so that it's copied to the output directory on build? - Theodoros Chatzigiannakis
Yes, I tried both ways. No dice... - nurdyguy
Once published, is your dll in the bin folder or not ? And is your dll 32bit? Try setting your web project to x86 or setting the app pool to 32bit in IIS. - Chris
I am compiling the project using 32bit. When I first published the project to the host it would not run. Once I clicked "Enable 32bit support" on my host's control panel the site became accessible. There aren't any IIS specific controls though. - nurdyguy
As far as the dll being in the bin folder, I've tried running it from multiple locations, including the bin. - nurdyguy

1 Answers

0
votes

Try right clicking on the reference in your project, click on properties and making sure it is set to copy local.