5

I want to execute a C++ .exe which depends on DLLs by means of Azure Functions. It works on my local machine as well as when starting the exe with kudo console.

Like in post Run .exe executable file in Azure Function suggested I prepared the run.csx and loaded up the .exe and DLLs in the same Folder "D:\home\site\wwwroot\QueueTriggerCSharp1\".

It works when no DLLs in the C++ Code is required. Otherwise C++ doesn't find the DLLs (which are in the same Folder as the .exe) and the exit code is -1073741701. I get the same exit code, if I don't upload the DLLs.

Where should I load the DLLs or could there be another reason for it?

The run.csx-Code:

using System;
using System.Threading;
using System.Diagnostics;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    string WorkingDirectoryInfo =@"D:\home\site\wwwroot\QueueTriggerCSharp1\";
    string ExeLocation = @"D:\home\site\wwwroot\QueueTriggerCSharp1\WriteDatebase2.exe";
    Process proc = new Process();
    ProcessStartInfo info = new ProcessStartInfo();
    info.WorkingDirectory = WorkingDirectoryInfo;
    log.Info($"WorkingDirectory: {info.WorkingDirectory}");
    info.FileName = ExeLocation;
    info.Arguments = "";
    info.UseShellExecute = false;
    info.CreateNoWindow = true;
    proc.StartInfo = info;
    proc.Start();
    proc.WaitForExit();
    int exitcode=proc.ExitCode;
    log.Info($"ExitCode: {exitcode}");
}

The same error occurs when I start the exe with a python azure function. Starting the python script in kudo console works.

Does anyone have similar issues?

Can anyone help me? Thanks!

Chris
  • 201
  • 2
  • 7
  • Please start with [this guidance](https://github.com/projectkudu/kudu/wiki/Isolating-WebJobs,-Functions-and-Deployment-script-issues). Basically, try to run the exe directly from Kudu Console. Does that fail too? – David Ebbo Sep 18 '18 at 18:45
  • 1
    Thanks for your repIy! It works! What could be the reason that it works from Kudo Console and does not work in azure functions? – Chris Sep 19 '18 at 07:19
  • Hmmm, that's puzzling, I'm not sure why it wouldn't work. Another test to try to isolate: write a little Console app with the code you have in your function, and run that Console app from Kudu console (but place it in a different folder). – David Ebbo Sep 20 '18 at 03:21
  • 1
    I wrote a Console app with the same method like in azure function (invoking the C++ exe with DLLs) and placed the resulting exe at different places. If I execute the Console app with Kudo console, it works. If I execute the Console app with azure functions, the Console app works, but the C++ exe fails with the same exitcode as before. – Chris Sep 20 '18 at 09:11
  • 1
    Sorry, I'm at a loss to explain it. Would probably need to look at a live repro. – David Ebbo Sep 20 '18 at 17:17
  • 1
    Too bad, thanks anyway. If you think of anything else, you can get in touch. – Chris Sep 21 '18 at 13:29
  • 1
    Have you found a solution for this? I have the same problem. – MaticDiba Oct 18 '18 at 07:02
  • No, sorry. I'm now using a workaround without DLLs. – Chris Oct 18 '18 at 09:08

3 Answers3

1

You need to bring your EXE or DLL with your Azure Function code. THis can be done during the deployment or manually with the KUDU interface. Then refer the EXE or DLL from in your Azure Function.

Here a 2-minute video that explains how to do it: Microsoft Developer - Execute an Exe in Azure

Frank Boucher
  • 1,834
  • 20
  • 25
0

Based on a meeting I just had with Microsoft Support, there is no way to do this.

Azure Functions is a very controlled (sandboxed) environment where access to system32 directory prevents EXE operation, despite the necessary DLLs being adjacent to the EXE.

I have found that an EXE with DLLs works fine on server/core but will not work on nanoserver. So I suspect Functions might use nanoserver, which could be the problem.

Getting your C++ working on nanoserver might be the gateway to Functions. But even if it doesn't get you to Functions, you can benefit from the drastically lower footprint of nanoserver. However, I'm not that optimistic about DLL-based EXEs running on nanoserver. Maybe statically linked EXEs is an option.

A co-worker actually had some console apps running in Functions some time ago but it has since stopped working.

EDIT: Just learned recently that nanoserver will never support 32-bit apps (not sure about 64-bit)

Peter L
  • 2,921
  • 1
  • 29
  • 31
0

I know it's an old question and maybe back then the situation was different, but I've just encountered the same issue and managed to solve it by delaying a load of a dll. So you have two options:

  1. Don't link your exe with the import library of the dll. Use LoadLibrary and GetProcAddress instead, or
  2. Keep linking your exe with the import library, but mark the dll as delay-loaded. Using Visual Studio you can do that by adding the dll filename to Configuration Properties->Linker->All Options->Delay Loaded Dlls input field.
undermind
  • 1,779
  • 13
  • 33