Problem using PnP Core GetAzureADAppOnlyAuthenticatedContext() with Azure Functions runtime.


I was working on an Azure Function recently that used the OfficeDevPnPCore AuthenticationManager() class with the GetAzureADAppOnlyAuthenticatedContext() method to get an app only authentication context.


new AuthenticationManager().GetAzureADAppOnlyAuthenticatedContext();

I was running into the very helpful error message of “Object reference not set to the instance of an object”.

After a little digging around I came across the following GitHub issue when pointed me in the right direction. https://github.com/SharePoint/PnP-Sites-Core/issues/1568

The problem seems to be with the latest runtime. I was running version 1.0.9 of the Azure Functions Core Tools to locally debug the function.

If you look at the app settings for your function in the portal, you will see that there is a setting called “FUNCTIONS_EXTENSION_VERSION” and this will be set to the value ~1 which means use the latest runtime.

The solution to being able to run this above code on Azure was to force the runtime to use a particular version. I set mine to 1.0.11388 which got everything working again.

functionsissue1

 

However I still needed to debug the function locally so I needed to update my local version of the core tools.

If you open a command prompt and type

func

you will see which runtime you have installed.

functionsissue2

As you can see I had version 1.0.9 installed. I looked through the releases on GitHub at https://github.com/Azure/azure-functions-core-tools/releases and decided to downgrade my tools to version 1.0.7.

After downgrading to version 1.0.7 I found that the above app only auth call started to work again.

functionsissue3

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s