如何在 Azure 函数中引用多个外部程序集?

How to reference multiple external assemblies in an Azure function?

到目前为止,我的 Azure 函数只依赖于一个外部程序集 (Assembly1),并且运行良好。

但是,最近我们不得不进行一些更改,因此现在有两个外部程序集,其中 Assembly1 引用 Assembly2。

我部署了与 Assembly1 相同的 Assembly2(我的意思是,将 .dll 复制到 Azure 函数的 "bin" 文件夹,并使用“#r Assembly2”语句将其导入到 Azure 函数中。

这给了我以下编译错误 -

Exception while executing function: Functions.ProcessCsvRows. Assembly1: Could not load file or assembly 'Assembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Function started (Id=dc837832-9303-4ae4-a8ae-133ab531250c) Unable to find assembly 'Assembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Are you missing a private assembly file?

有关此的更多详细信息,请在下方找到代码 -

#r "Assembly1"
#r "Assembly2"

using System;
using System.Net;
using Newtonsoft.Json;
using System.IO;
using System.Collections.Generic;
using System.Configuration;
using Assembly1.Entities;

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log){
    var jsonContent = await req.Content.ReadAsStringAsync();
    dynamic data = JsonConvert.DeserializeObject(jsonContent.ToString());
    ProcessCsvFileContents_Result _processResponse = await DataProcessor.ProcessCsvFileContents(data.FileContent.ToString(), connectionString, clientId, redirectUrl); // DataProcessor exists in Assembly1 only
    -- response processing code -- 
}

非常感谢您对此提供的任何帮助。

尼尔曼

私有程序集应使用其扩展名(例如 .dll)进行引用。看起来你 运行 执行失败(编译成功)

能否请您检查以下内容:

  1. 确保 assembly1.dll 和 assembly2.dll 都位于该函数文件夹中的 bin 文件夹中
  2. 如果您在部署文件之前更新了函数引用,绑定可能会失败。能否请您重新启动您的 Function App(重新启动网站)

希望对您有所帮助!