Nirman Nirman - 10 months ago 62
C# Question

How to reference multiple external assemblies in an Azure function?

Till now my Azure function was relying on only one external assembly (Assembly1), and it was working fine.

However, recently we had to do some changes due to which there are now two external assemblies where Assembly1 is referencing Assembly2.

I have deployed the Assembly2 the same was as Assembly1 (I mean, copied .dll to the "bin" folder of Azure function, and imported it in the Azure function using "#r Assembly2" statement.

This gives me following compilation error -

Exception while executing function: Functions.ProcessCsvRows.
Assembly1: Could not load file or assembly 'Assembly2,
Version=, 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=, Culture=neutral,
PublicKeyToken=null'. Are you missing a private assembly file?

Please find below the code for more details on this -

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

Much appreciated for any help on this.

Answer Source


Private assemblies should be referenced with their extension (e.g. .dll). Looks like you're running into an execution failure (compilation succeeds)

Can you please check the following:

  1. Make sure both, assembly1.dll and assembly2.dll are located in the bin folder, in that function's folder
  2. If you had updated your function reference before the file was deployed, binding could have failed. Can you please restart your Function App (restart the site)

Hope this helps!