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=22.214.171.124, 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=126.96.36.199, 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=188.8.131.52, 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.
- System.Text.Json.JsonPropertyName not working for CosmosDb in .NET Core/5? - October 19, 2021
- Errors loading an assembly that’s using Microsoft Graph API - October 12, 2021
- ILogger binding suddely failing for Azure Functions – what to do? - October 5, 2021