azure webjob can't find dll

Question!

I have a simple c# console application that uses a c++ dll, it works perfectly in my PC.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("ConsoleApplication2.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int mainn();

        static void Main(string[] args)
        {
            int num = mainn();
        }
    }
}

I zipped this console application with its dll and all debug files and upload it to a continuous webjob, so it looks like this: http://i.imgur.com/wWfE6lG.png when running inside azure this error happens:

[07/15/2015 22:10:49 > 223c43: SYS INFO] Run script 'ConsoleApplication1.exe' with script host - 'WindowsScriptHost'
[07/15/2015 22:10:49 > 223c43: SYS INFO] Status changed to Running
[07/15/2015 22:10:49 > 223c43: ERR ] 
[07/15/2015 22:10:49 > 223c43: ERR ] Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'ConsoleApplication2.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[07/15/2015 22:10:49 > 223c43: ERR ]    at ConsoleApplication1.Program.mainn()
[07/15/2015 22:10:49 > 223c43: ERR ]    at ConsoleApplication1.Program.Main(String[] args) in c:\Users\Juan Jose\Desktop\NAT middleman\ConsoleApplication1\Program.cs:line 17
[07/15/2015 22:10:49 > 223c43: SYS ERR ] Job failed due to exit code -532462766
[07/15/2015 22:10:49 > 223c43: SYS INFO] Process went down, waiting for 60 seconds

which means it can't find ConsoleApplication2.dll but in the image you can see it is right there, how do I fix this?

By : Wusevar i


Answers

I would first try setting the environment to the current directory:

Environment.CurrentDirectory

If this doesn't work I'd fall back on the probing element in your app.config.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin2\subbin;bin3"/>
      </assemblyBinding>
   </runtime>
</configuration>

ref: https://msdn.microsoft.com/en-us/library/823z9h8w.aspx



I solved this by changing in visual studio this option: project propertires->C/C++->Code Generation->Runtime Library-> change this option to Multi-threaded(/MT). Rebuilding ConsoleApplication2.dll again then passed it to azure and it worked.

By : Wusevar i


First I would make sure you have a reference to your dll in the project references. To do this right click on the references tab in the solution tree and click add reference. Then under browse find your dll and check it into your project. If its already there checked then you have referenced your dll. Then I would check your dll and make sure its not read-only.

Hope this helps;)

By : JohnJ


This video can help you solving your question :)
By: admin