Azure Function with PnP - Missing Microsoft.IdentityModel.Extensions.dll

Let's say you want to build a Azure Function for site provisioning in SharePoint Online. You think, I could use the .Net PnP library for that! And you're right. However, I ran into the problem of a missing dll when trying to authenticate to SharePoint using App-only credentials.
It turns out the the Nuget packages for PnP are missing a dependency that is present on your developer environent but not with the Azure App service you deploy the Function to.
The file that is missing is Microsoft.IdentityModel.Extensions.dll.
This file is available in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.IdentityModel.Extensions\v4.0_2.0.0.0__69c3241e6f0468ca

In order to get the Azure Function working, add this file in a folder in your Azure function solution. Then click on it and in the properties window select Embedded resource for Build action and Copy always for Copy to output directory. This will make sure the dll is copied into the bin folder of the App service and that it is loaded when the Azure Function starts.

Hopefully this article helps someone in fixing this issue when using PnP in Azure Functions!

Show Comments