Some men want to watch the build fail

Errors loading an assembly that’s using Microsoft Graph API

This post was most recently updated on February 8th, 2022.

2 min read.

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 that 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

Problem

There are a couple of different errors you might get. Let me try to list some examples. I 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=5.0.0.0, 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=5.0.0.0, 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=5.0.0.0, 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?

Solutions

Time needed: 15 minutes

How do you fix different “Could not load file or assembly” errors when building a solution with multiple projects referencing one another?

  1. 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…

  2. 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…

  3. 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:

    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

    To your .csproj file. It’ll disable some (apparently buggy) output folder cleaning from your Azure Functions build.


References

mm
5 1 vote
Article Rating
Subscribe
Notify of
guest

2 Comments
most voted
newest oldest
Inline Feedbacks
View all comments