Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

How to add assembly references to an Azure Function App

Discussion in 'Official Microsoft News' started by benjaminperkins, Apr 13, 2017.

Thread Status:
Not open for further replies.
  1. benjaminperkins

    benjaminperkins Guest

    Blog Posts:
    I wanted to do this and I found these articles helpful: #AzureFunction #Azure #Csharp

    • Azure Functions C# developer reference –> see Referencing External Assemblies
    • How to make a simple DLL as an assembly reference just for fun
    • Could not load file or assembly … The system cannot find the file specified SOLVED

    It did take some hours, but I finally got it donw. Here is how I did it.

    • Create an Azure Function
    • Add the assembly to the BIN directory using KUDU
    • Include the assembly and code the Azure Function to use it
    • Test the Azure Function
    Create an Azure Function

    There is nothing overlly exciting about this part, so just create the Azure Funtion, you know the deal.


    Figure 1, Create an Azure Function

    I did create a Custom function, I.e. not a Timer, Data processing or Webhook + API one. Instead I created an empty/default HttpTrigger-Csharp one, see Figure 2.


    Figure 2, Create an Azure Function, default HttpTrigger

    Add the assembly to the BIN directory using KUDU

    I have discussed what SCM / KUDU is here. Knowing that you can then access the SCM / KUDU console by adding the SCM to the domain shown in the Overview tab in the portal, as seen in Figure 3.


    Figure 3, Accessing SCM / KUDU Azure Function

    After you access SCM / KUDU for the Azure Function, navigate to the method you created and within it, create a BIN directroy and place the assemyl withn it, as seen in Figure 4. The creation of the benjamin.dll is describe here, referenced earlier.


    Figure 4, Accessing SCM / KUDU Azure Function, add a BIN directory and the assembly

    Include the assembly and code the Azure Function to use it

    As seen in the code snippet below you include the assembly using the #r identifier. You might be able to make it work using a relative path, but I included the absolute path and the name of the dll including the file extensiion. Also add the using declaration so that the methods within the DLL can be accessed. There was no intellisense, so I had to know the proper way to call the method.

    #r "D:homesitewwwrootGreetingsAssemblyReferencebinbenjamin.dll"

    using System.Net;
    using benjamin;

    public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
    string name = req.GetQueryNameValuePairs()
    .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)

    var greetings = benjamin.Greetings.Hello(name);

    dynamic data = await req.Content.ReadAsAsync<object>();

    name = name ?? data?.name;

    return name == null
    ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
    : req.CreateResponse(HttpStatusCode.OK, greetings);

    Then I just made some simple changes to the default Azure Function to send back my Greetings and tested it using CURL as seen in Figure 5.


    Figure 4, testing an assembly with an Azure Function, add a BIN directory and the assembly

    And it worked just as expected.

    Continue reading...
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software