【问题标题】:How to reference multiple external assemblies in an Azure function?如何在 Azure 函数中引用多个外部程序集?
【发布时间】:2016-11-14 09:51:23
【问题描述】:

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

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

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

这给了我以下编译错误 -

执行函数时出现异常:Functions.ProcessCsvRows。 Assembly1:无法加载文件或程序集“Assembly2, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null' 或其之一 依赖关系。该系统找不到指定的文件。功能 已启动 (Id=dc837832-9303-4ae4-a8ae-133ab531250c) 无法找到 程序集'Assembly2,版本=1.0.0.0,文化=中性, PublicKeyToken=null'。您是否缺少私有程序集文件?

请在下面的代码中找到更多详细信息 -

#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 -- 
}

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

【问题讨论】:

  • 是的,我已经提到了,我正在执行那里列出的所有步骤,除了我在相关 Azure 函数的 bin 文件夹中上传的 DLL 文件的位置,因为我的是私有程序集(并且不共享)。正如我所说,这一切都很好,直到我只需要使用“Assembly1”。一旦我介绍了“Assembly2”,我就开始面临这个问题。
  • 所以你的函数文件夹中有一个包含你的dll的bin文件夹?根据文档here,这应该可以工作。尝试按照文档将“.dll”添加到程序集名称的末尾,看看是否有帮助。

标签: c# azure azure-functions azure-logic-apps


【解决方案1】:

尼尔曼,

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

请检查以下内容:

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

希望这会有所帮助!

【讨论】:

  • 感谢 Fabio.. 在 Azure 上重新启动站点成功了.. 非常感谢 :)
  • Nirman,我正在查看这个答案并注意到,不知何故,我的参考指令错误(意思是简单的文件名,意思是没有路径,而是说程序集)。我已经在上面澄清了,但我假设你已经这样做了,否则你可能会遇到问题,但在引用私有程序集时应该使用文件扩展名。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-05
  • 1970-01-01
  • 2017-01-18
相关资源
最近更新 更多