Could not load file or assembly System.Fabric with Azure Functions

2

Are there any restrictions with packages you can use with Azure Functions. I have researched as much as I can and it doesn't seem so, however when I try creating an Azure Function that references the package "Microsoft.ServiceFabric" I get the following error:

System.Private.CoreLib: Exception while executing function: ScaleDownServiceFabrics. FunctionApp2: Could not load file or assembly 'System.Fabric, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'System.Fabric, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

I have tried both Azure Func and.1 and 2, and .Net Framework and .Net Core with no luck.

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Fabric;

namespace FunctionApp5
{
  public static class Function1
  {
    [FunctionName("Function1")]
    public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, ILogger log)
    {
      log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
      FabricClient client = new FabricClient();
    }
  }
}

Is this possible, or a limitation of Azure Functions in Visual Studio - if so, what packages are acceptable?

c#
azure
azure-functions
azure-service-fabric
azure-functions-core-tools
asked on Stack Overflow Nov 13, 2018 by tank104 • edited Nov 13, 2018 by tank104

3 Answers

3

Diego and Suraj have pointed out the cause, conflict between 64 and 32 bit.

Two points to fix

  1. Set build platform to x64 like what you have done.
  2. Get x64 Function runtime. Functions work on Function runtime(contained in Azure Function core tools), but the default bit is x86 downloaded by VS.

To get x64 bit in an easy way, let's use Nodejs to install Azure Functions Core Tools from NPM.

After installation, in cmd input npm i -g azure-functions-core-tools --unsafe-perm true to get Function core tools.

Then set project debug properties(right click on your project>Properties>Debug blade).

  1. Set Launch type to Executable

  2. Set Executable path to %appdata%\npm\node_modules\azure-functions-core-tools\bin\func.exe.

  3. Add Application arguments start.

answered on Stack Overflow Nov 14, 2018 by Jerry Liu
3
  • ServiceFabric packages are x64 bit, if your function target 32bit it will fail. Try the solution proposed by Jerry Liu
  • Service Fabric Packages have to be added as packages instead of reference the dll directly in the project, because of the dependencies on other libraries. You should add the NuGet package Microsoft.ServiceFabric.
  • Microsoft.ServiceFabric latest version 6.3.x targets .Net Standard 2.0 and .Net Framework from 4.5 to 4.7.1, make sure you are using any of these on your project.
  • Make sure the Microsoft.ServiceFabric DLLs are being copied to the bin folder when built\deployed.
  • When you use FabricClient outside the cluster, you have to specify the settings and credentials, otherwise you won't be able to connect to the cluster. See this example and this docs.
  • FabricClient uses Service Fabric API to interact with the cluster, if are having issues with the packages, another option is use HttpClient and make the requests to the API and avoid the packages conflicts
answered on Stack Overflow Nov 14, 2018 by Diego Mendes
1

I run into exactly same issue as @tank140 commented in original post:

Unable to load DLL 'FabricClient.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

More details in another question that I fired on the issue. As answer, it was confirmed that SF Client API for .NET requires that SF runtime is installed on the platform, which is not supported in Azure Functions.

answered on Stack Overflow Feb 27, 2019 by potsi • edited Mar 1, 2019 by potsi

User contributions licensed under CC BY-SA 3.0