Azure Functions 上的 Service Fabric Client - 无法加载 DLL 'FabricClient.dll' 或其依赖项之一
Service Fabric Client on Azure Functions - Unable to load DLL 'FabricClient.dll' or one of its dependencies
我在 Azure Functions 上有一个应用程序 运行ning,包括一个 class 使用 Service Fabric 客户端 API 在 Service Fabric 集群上管理应用程序和服务 运行ning对于.NET。
当我 运行 应用程序在本地以调试模式从 Visual Studio 工作时,与 Service Fabric Cluster 的连接按预期工作。当我将应用程序部署到 Azure Functions 时,使用 Service Fabric Client API 导致异常:
Execution result: Unable to load DLL 'FabricClient.dll' or one of its
dependencies: The specified module could not be found. (Exception from
HRESULT: 0x8007007E)
下面的简化代码。
// SfClientApiHelper.cs
using System.Fabric;
using System.Fabric.Description;
namespace MyService
{
class SfClientApiHelper
{
private FabricClient Client { get; set; }
. . .
public SfClientApiHelper()
{
. . .
this.Client = new FabricClient();
}
// ClassUsingSfClientApiHelper.cs
. . .
SfClientApiHelper sfHelper = new SfClientApiHelper(); // => exception
我在 Visual Studio 项目上安装了 Microsoft.ServiceFabric 包。我已经从 here, and built target is set to x64; these guided and here). Project is published to Azure Functions using zip deployment, I checked from zip deployment package that it contains library 'System.Fabric.dll', and checked that it is x64 using CorFlags.exe as guided here 安装了 win-x64 版本的 Azure Functions CLI 工具。
另一个 Whosebug 关于同样的问题,在讨论中其他可怜的家伙 'tank140' 最终遇到了同样的异常。根据我的理解,讨论没有达成任何解决方案。
在我的 运行ning 本地工作的开发 PC 上找到丢失的 DLL。 FabricClient.dll 位于文件夹 C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code。可能是因为我在 PC 上安装了 Service Fabric SDK。
如何将此 DLL 包含在 Function Apps 项目中以部署到 Azure Functions?
我查看了我的代码中引用的 FabricClient class 的定义(见下图),根据 VisualStudio,class 是在程序集 'System.Fabric.dll' 中定义的。如图所示,这包含在带有 NuGet 包 'Microsoft.ServiceFabric' 的项目中。如前所述,此程序集也包含在部署 zip 包中。在我看来,VS 项目和现实有些不匹配; FabricClient class 可从未在依赖项中声明的程序集在本地部署中访问。
您需要顺丰运行平台安装时间。
我不确定这是否可行,但也许您可以使用预装 运行time 的容器来实现。
有一张名为 microsoft/service-fabric-reliableservices-windowsservercore
的图片可供您使用。
并且 here's how 创建一个 Azure 函数,该函数 运行 是一个带有自定义图像的 (Linux) 容器。
如果您只是创建一个管理其他应用程序和服务的服务,并且 运行 它在集群上,那么它可能 简单很多。
MS 对我的支持请求的答复:
Service Fabric .Net API is not available for Azure functions because
is requires the Service Fabric SDK and runtime to be installed on the
platform which cannot be done with an Azure function.
So in your case
the options available would be to either rebuild the application to
use the Service Fabric REST API and this should be able to run on
Azure Functions.
Another option, besides running on a virtual machine, would be to
create a custom windows container in which you install the Service
Fabric SDK and runtime and them deploy it for example in an Azure
Container.
我在 Azure Functions 上有一个应用程序 运行ning,包括一个 class 使用 Service Fabric 客户端 API 在 Service Fabric 集群上管理应用程序和服务 运行ning对于.NET。
当我 运行 应用程序在本地以调试模式从 Visual Studio 工作时,与 Service Fabric Cluster 的连接按预期工作。当我将应用程序部署到 Azure Functions 时,使用 Service Fabric Client API 导致异常:
Execution result: Unable to load DLL 'FabricClient.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
下面的简化代码。
// SfClientApiHelper.cs
using System.Fabric;
using System.Fabric.Description;
namespace MyService
{
class SfClientApiHelper
{
private FabricClient Client { get; set; }
. . .
public SfClientApiHelper()
{
. . .
this.Client = new FabricClient();
}
// ClassUsingSfClientApiHelper.cs
. . .
SfClientApiHelper sfHelper = new SfClientApiHelper(); // => exception
我在 Visual Studio 项目上安装了 Microsoft.ServiceFabric 包。我已经从 here, and built target is set to x64; these guided
另一个 Whosebug
在我的 运行ning 本地工作的开发 PC 上找到丢失的 DLL。 FabricClient.dll 位于文件夹 C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code。可能是因为我在 PC 上安装了 Service Fabric SDK。 如何将此 DLL 包含在 Function Apps 项目中以部署到 Azure Functions?
我查看了我的代码中引用的 FabricClient class 的定义(见下图),根据 VisualStudio,class 是在程序集 'System.Fabric.dll' 中定义的。如图所示,这包含在带有 NuGet 包 'Microsoft.ServiceFabric' 的项目中。如前所述,此程序集也包含在部署 zip 包中。在我看来,VS 项目和现实有些不匹配; FabricClient class 可从未在依赖项中声明的程序集在本地部署中访问。
您需要顺丰运行平台安装时间。
我不确定这是否可行,但也许您可以使用预装 运行time 的容器来实现。
有一张名为 microsoft/service-fabric-reliableservices-windowsservercore
的图片可供您使用。
并且 here's how 创建一个 Azure 函数,该函数 运行 是一个带有自定义图像的 (Linux) 容器。
如果您只是创建一个管理其他应用程序和服务的服务,并且 运行 它在集群上,那么它可能 简单很多。
MS 对我的支持请求的答复:
Service Fabric .Net API is not available for Azure functions because is requires the Service Fabric SDK and runtime to be installed on the platform which cannot be done with an Azure function.
So in your case the options available would be to either rebuild the application to use the Service Fabric REST API and this should be able to run on Azure Functions.
Another option, besides running on a virtual machine, would be to create a custom windows container in which you install the Service Fabric SDK and runtime and them deploy it for example in an Azure Container.