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

this project type requires microsoft azure service fabric sdk version 3.0 or higher
install service fabric powershell module
service fabric explorer download
service fabric for visual studio
service fabric for vs 2017
uninstall service fabric sdk
service fabric sdk 2017

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?

'Could not load file or assembly 'System.Fabric.Management , 'Could not load file or assembly 'System.Fabric.Management And then installed 'Microsoft Azure Service Fabric SDK 2.8.232' using Web  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.

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.

Could not load file or assembly 'System.Fabric, Version=5.0.0.0 , The same problem without ASP.NET core. Just added new stateless service several days ago and SF isn't able to instantiate it in Azure, but  When running .NET Core 2.0 Stateful Service which uses FabricClient System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Fabric.Management

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.

UpgradeSortOrder Enum (System.Fabric), Private.CoreLib: Exception while executing function: ScaleDownServiceFabrics. FunctionApp2: Could not load file or assembly 'System.Fabric, Version=6.0.0.0,  Could not load file or assembly 'System.Fabric.Management, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. The System.Fabric.dll and System.Fabric.Management.ServiceModel.dll are located in the folder as expected.

Azure Functions v 2.0 HttpTrigger with CosmosDB Client Tips, Enumerates the ways upgrade domains can be sorted. Definition. Namespace: System.Fabric. Assembly: System.Fabric.dll. Package: Microsoft.ServiceFabric  Hi, I get this exception with this setup: vs2017 with azure sdk, create new azure function, queue trigger, deploy, it works. Could not load file or assembly

Azure Functions DocumentClient could not load type from assembly , NetCore 2.0 based Azure Functions Environment with CosmosDB. I'd like to System.Private.CoreLib: Could not load file or assembly 'System.Net. Running in latest Service Fabric. Using Microsoft.Azure.DocumentDB. Exception while executing function: GetTaskCounts Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.1.3001, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file.

Archives · James Sturtevant, Azure.ServiceBus'Could not load file or assembly 'AutoMapper' in .net projectCould not load file or assembly System.Fabric with Azure  Azure AD v2.0 Powershell Module: "Could not load file or assembly 'Microsoft.Open.Azure.AD.CommonLibrary.Resources"

Comments
  • ServiceFabric packages are x64 bit, if your function target 32bit it will fail. Can you check that? Another point is, you have to add the dependencies as packages instead of reference the dll directly in the project, because of the dependencies on other libraries.
  • @tank: Diego has provided good checklist for the errors, also can you build the solution with the same and see if you get any errors on error list window, and also make sure to check the solution has all the packages(if using nuget just try to update the packages) and any other referencing dll's , and then test once.
  • @diego - I tried changing to x64 (the default with new Azure Function in VS is Any CPU). But got this error: [13/11/2018 10:08:38 PM] A host error has occurred. [13/11/2018 10:08:38 PM] System.Private.CoreLib: Could not load file or assembly 'FunctionApp5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.I don't think this is related.
  • @diego - I definitely referenced as a package not DLL. Package is "Microsoft.ServiceFabric". I updated the above code to the simplest possible way to replciate the issue.
  • @suraj - I am not sure what you mean by "build the solution with the same". Do you mean in x64? If so that causes issues above. All referencing DLLs are in the bin. Only thing I noticed was that System.Fabric.Dll has File Version 6.0.0.0 but product version 6.3.187.9494 - although I think this counts as 6.0.0.0
  • Hi Diego, many thanks for that - it was the issue! Is there an easy way to tell if a package is 64 bit only?
  • I knew it because I suffered a lot with this Library and is the first check I do. There are many ways, I generally use ILSpy, but you can find many alternatives here: stackoverflow.com/questions/270531/…
  • one other question - when I build and deploy this in VSTS - I get this error in Azure Function App: Function (FeedExports) Error: Unable to load one or more of the requested types. 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). I have downloaded the file contents from the Azure Function App and the DLL is there. Any ideas?
  • NEeded to change the Azure function app from 32-bit to 64-bit sorted it.
  • I am getting this now in the logs: Unable to load DLL 'FabricClient.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) I guess as the client is not installed on the App Service. If you got it working - did you just add this DLL to deployment?
  • Thanks Jerry - your guide to run in 64-bit sorted it.
  • What I ended up having to do is create an app and run it in the Service Fabric itself unfortunately.