无法使用 Azure Functions 加载文件或程序集 System.Fabric

Could not load file or assembly System.Fabric with Azure Functions(无法使用 Azure Functions 加载文件或程序集 System.Fabric)

本文介绍了无法使用 Azure Functions 加载文件或程序集 System.Fabric的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可用于 Azure Functions 的包是否有任何限制.我已经尽可能多地进行了研究,但似乎并非如此,但是当我尝试创建一个引用包Microsoft.ServiceFabric"的 Azure 函数时,我收到以下错误:

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:执行函数时出现异常:ScaleDownServiceFabrics.FunctionApp2:无法加载文件或程序集'System.Fabric,版本=6.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'.无法找到或加载特定的文件.(来自 HRESULT 的异常:0x80131621).System.Private.CoreLib:无法加载文件或程序集'System.Fabric,版本 = 6.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'.

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'.

我尝试过 Azure Func 和 .1 和 2,以及 .Net Framework 和 .Net Core,但都没有成功.

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();
    }
  }
}

这是可能的,还是 Visual Studio 中 Azure Functions 的限制 - 如果是,哪些包是可以接受的?

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

推荐答案

  • ServiceFabric 包是 x64 位的,如果您的功能目标是 32 位,它将失败.试试 Jerry Liu 提出的解决方案
  • Service Fabric 包必须作为包添加,而不是直接在项目中引用 dll,因为它依赖于其他库.您应该添加 NuGet 包 Microsoft.ServiceFabric.
  • Microsoft.ServiceFabric 最新版本 6.3.x 针对 .Net Standard 2.04.5 中的 .Net Framework4.7.1,请确保您在项目中使用了这些中的任何一个.
  • 确保在构建部署时将 Microsoft.ServiceFabric DLL 复制到 bin 文件夹中.
  • 当您在集群外使用 FabricClient 时,您必须指定设置和凭据,否则您将无法连接到集群.请参阅 this 示例和 this 文档.
  • FabricClient 使用 Service Fabric API 进行交互对于集群,如果包有问题,另一种选择是使用 HttpClient 并向 API 发出请求并避免包冲突
    • 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 builtdeployed.
    • 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
    • 这篇关于无法使用 Azure Functions 加载文件或程序集 System.Fabric的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法使用 Azure Functions 加载文件或程序集 System.Fabric