Man, do I run into all kinds of issues with the smallest Azure Functions that I develop. And it’s mostly my fault.
The silver lining is that you’re here to read this article, so you probably ran into this same stuff. Well – you should be happy to hear this article describes fixes to a couple of issues – let’s see if they help you out as well!
The article probably largely applies to any situation where you have a project referencing another project and trying to figure out the dependencies during runtime, but I have mostly encountered these
There are a couple of different errors you might get. Let me try to list some examples. I really ran into each of these..
The one I got first was this:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=126.96.36.199, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=188.8.131.52, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Or a similar one for a different assembly:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Text.Encodings.Web, Version=184.108.40.206, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Or even this one:
A host error has occurred during startup operation '[guid]'. [2021-09-23T09:01:27.488Z] Microsoft.Azure.WebJobs.Extensions.CosmosDB: Method not found: 'Microsoft.Azure.WebJobs.IWebJobsExtensionBuilder Microsoft.Azure.WebJobs.WebJobsExtensionBuilderExtensions.ConfigureOptions(Microsoft.Azure.WebJobs.IWebJobsExtensionBuilder, System.Action`3)'. Value cannot be null. (Parameter 'provider')
(The last one was fixed by steps 1 & 2)
And then – what do you do to fix them?
Time needed: 15 minutes.
How to fix different “Could not load file or assembly” errors when building a solution with multiple projects referencing one another?
- Add PackageReference to your referencing project
This is caused by a referenced project’s PackageReferences not swimming downstream to your referencing project. Simply add the same PackageReference node to the referencing project.
Didn’t work? Ok, let’s go on…
- Downgrade your packages
For me, downgrading the Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Abstractions packages to version 2.1.0 in both projects (referenced and referencing – in my case a class library, and the Azure Function project referencing it), actually helped.
Well, it helped for a week, until I ran into the next issue…
- Disable the automated (and buggy) output cleaning step
This step might help you if the build for your Azure Functions project is the one throwing the error!
Add this line:
To your .csproj file. It’ll disable some (apparently buggy) output folder cleaning from your Azure Functions build.
- Azure Function build fails with “Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: Microsoft.AspNetCore.Mvc.Core” - December 1, 2021
- How to update from deprecated Microsoft.Azure.Services.AppAuthentication to new and shiny Azure.Security.KeyVaults.Secrets? - November 23, 2021
- Fixing Blazor WebAssembly .NET 6 MSAL authorization bug - November 16, 2021