2

I am facing strange issues with privates assemblies in azure functions, I have an Azure Function App with five functions which have a shared bin folder where I place my assemblies, these assemblies in turn depend on Entity Framework and LinqKit for which I have added dependencies in all the project.json files for each function but private assemblies are unable to get reference to these and failing. Please help. Project.json --

{
  "frameworks": {
    "net46":{
      "dependencies": {
         "EntityFramework": "6.1.3",
         "Newtonsoft.Json": "9.0.1",
         "LinqKit": "1.1.7.2"
      }      
    }
   }
}

To clarify further in my Function App I have five different functions which depend on 2 private assemblies and I do not want to keep separate copies (as this might cause different versions of the same dll in different folder causing issues) in each function so I have created a shared bin folder from where the private assemblies are referenced but the issue happens as these private assemblies further depend on some nuget packages which they are not able to find them --

#r "..\bin\Marketware.Domain.dll"
#r "..\bin\Marketware.AzureIntegration.dll"

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics.Eventing.Reader;
akhil
  • 381
  • 2
  • 13
  • Possible duplicate of [Execute pre-compiled .NET code as Azure Function](http://stackoverflow.com/questions/36436917/execute-pre-compiled-net-code-as-azure-function) – Thomas Oct 20 '16 at 00:21

2 Answers2

4

If you want to use your private assembly (not from nuget) you have to do this:

  1. Connect to Functions App ftp
  2. Create bin folder in folder with your function (where is run.csx)
  3. Upload your custom assembly to newly created bin folder
  4. Update function code and add reference

Unfortunately this dll needs to be in each function folder where needed.

Example

#r "CustomAssembly.dll"

using System.Net;
using CustomAssembly;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    CustomAssemblyClass.MethodName(); // here call your method
    return req.CreateResponse(HttpStatusCode.OK, "");
}
Lukas Nespor
  • 1,238
  • 1
  • 14
  • 22
1

Will spend a bit of time trying to repro your scenario as, at a first glance, it should work as expected. In the meantime, a couple of options you have are:

1- When deploying your shared assemblies, copy all the binaries from your project output, including their dependencies. The shared assemblies folder will be in the probing logic and they would be resolved from there. This would also eliminate the need to have a project.json referencing the dependencies on each function.

2- Create a NuGet package for your shared assemblies and, on that package, specify your package dependencies (EF and LinqKit), publish that package to a private feed (which could be something like MyGet or even a folder in your function app). Your functions would only need to reference that package and not its dependencies, as those would be automatically resolved. You can find more information about using custom sources here: How do you use custom NuGet feeds with Azure Functions?

Although it may require a bit more work at first, both options have advantages over your original approach (including eliminating the need for the functions to be aware of indirect dependencies) and should be more reliable.

Hope this helps!

Community
  • 1
  • 1
Fabio Cavalcante
  • 12,328
  • 3
  • 35
  • 43
  • Thinking about the first approach as the code in my Function Code also depends on EF and LinqKit besides the Shared Assemblies will it be able to get a reference to these if I place them in the shared bin along with the shared assemblies – akhil Oct 20 '16 at 13:03
  • Yes, you could add those references as you do with the shared assemblies or continue to use nuget. – Fabio Cavalcante Oct 20 '16 at 14:20
  • And to be sure that's clear, the second approach would make those indirect dependencies available to your function code as well. – Fabio Cavalcante Oct 20 '16 at 14:27