Friday 22 September 2017

Azure Functions errors with "Could not load from "

Azure Functions kept throwing an error "Could Not Load <Type> from <Assembly>."
I had the correct DLL in the bin folder relative to the function, so what was wrong?

In the end I figured it out.

I had two versions of the same assembly. One in Function1/bin and the other in Function2/bin.

These functions and their folders are not independent. If you have two functions referencing the same named assembly then put it in the site's bin folder, not the function's bin folder.

To anyone stumbling on this:
The answer was that multiple versions of the same assemblies were located in the same function app, in different bin folders (different functions). Apparently, it would sometimes find a different version when loading assemblies, and that would cause the mentioned error.
There are two solutions:
  1. Preferably, start using the VS2017 tooling to build, test, and publish your functions. This puts all assemblies in the same bin folder and the whole development and publishing process resembles that of Webjobs.
  2. Alternatively, put all your assemblies in a shared folder, and reference that rather than specific bin folder for each function.

A function is not a unit of isolation with respect to assemblies. The Function App is the isolation point. Functions are a subcomponent of the App. This is a bit confusing when you think the whole service is marketed as Functions As A Service (FaaS) and Azure Functions. What you really are building is a Function App that comprises individual Functions.

No comments:

Post a Comment