4

Using libsodium-net for all of its security goodness in an Azure Service Fabric Reliable Service, on my local dev cluster everything is working fine (although I did have to set the libsodium-64.dll to copy to the output directory).

Unfortunately, when deployed to a real cluster in Azure it throws the following error:

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

I've checked by Remote Desktop-ing into one of the nodes and the DLL is copied across into the same directory as the service, exactly as it is in my dev cluster. Can't work out why it can't be found in production.

I've tried setting the PATH environment variable as suggested in this answer, and verified that it does actually get set - unfortunately that doesn't help.

Is there anything special I need to do to get ASF to pick up the DLL?

Edit: also tried adding the DLL to System32 on all the nodes, didn't solve it either.

Community
  • 1
  • 1
Tom Davies
  • 899
  • 6
  • 20
  • There really shouldn't be anything special here. Are you able to modify the service to print out what it thinks is in its working directory and also to check out the path? – masnider Jul 14 '16 at 22:30
  • Yeah didn't think there should be, logging `Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory)` shows "D:\SvcFab\_App\...\...Pkg.Code.1.0.0\libsodium-64.dll" as being in there. Path shows C:\Windows\system32, Windows, and the usual locations. – Tom Davies Jul 14 '16 at 23:19
  • @TomDavies and what `Environment.CurrentDirectory` is like? Could you please provide these paths both for production and your local env. – cassandrad Jul 15 '16 at 08:05
  • @cassandrad: `Environment.CurrentDirectory` is "C:\\SfDevCluster\\Data\\_App\\_Node_4\\XYZType_App12\\work" in my local environment, "D:\SvcFab\_App\XYZType_App9\work" for production. Printing the files out for "work" shows a similar collection of .SFlog files and files named as random GUIDs for both production and local. – Tom Davies Jul 15 '16 at 16:35
  • @TomDavies is it possible to find out platform and .NET Framework version of your library? – cassandrad Jul 15 '16 at 17:44
  • 1
    Thanks both - got there in the end. Turns out the DLL depends on the vcruntime140.dll which wasn't on the VM! – Tom Davies Jul 15 '16 at 23:45

1 Answers1

8

Turns out libsodium-64.dll depends on the Visual C++ Runtime, which didn't seem to be present on the Azure VMs. Ran Process Monitor as mentioned here and saw it was picking up "libsodium-64.dll" but failing on "vcruntime140.dll" - the exception message alone makes this pretty much impossible to work out.

Installed the Visual C++ Redistributable on the VMs and everything seems to be working fine now.

If anyone happens to run into the same problem, you can solve it by adding the following extension to the VM profile of the scale set in your ARM deployment template (VMSS -> properties -> virtualMachineProfile -> extensionProfile -> extensions):

{
    "name": "InstallVCRuntime",
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.7",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "fileUris": [
                "https://some.blob.storage.url/vc_redist.x64.exe"
            ],
            "commandToExecute": "vc_redist.x64.exe /q /norestart"
        }
    }
}

All it does is grab the installer, and run it silently. There didn't seem to be a public link to the redistributable, so I just downloaded it and put it into blob storage.

Tom Davies
  • 899
  • 6
  • 20
  • Worked for me after restarting the machines, also packaged a release build to keep debug dlls out. Thanks! – Dagrooms Jul 19 '16 at 21:10
  • Sorry for being so ignorant but where does one find this ARM deployment template if the cluster is created through the Azure Portal? – Johannes Heesterman Aug 04 '16 at 08:55
  • @JohannesHeesterman, no problem. You can export it from the Portal. Find your cluster, then go to Settings > Automation script and it'll give you the template along with various ways of deploying it. – Tom Davies Aug 04 '16 at 12:58