powershell: [BUG] Microsoft.Graph and PnP.PowerShell conflict (Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider') #2285

Notice

I have also reported this issue in the Microsoft.Graph repository (https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2285), but I would be really happy if you could also investigate the error from this side. Thank you.

Reporting an Issue or Missing Feature

When using the Microsoft.Graph and PnP.PowerShell module in the same script, the Get-MgGroup -All command fails with the following exception: Get-MgGroup_List: Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

The error occurs if the script is executed locally as well as an Azure Automation runbook.

We locally use PowerShell v7.3.6 and in Azure Automation we also use the latest PS7.2 runbooks. The latest Microsoft.Graph.* module version 2.4.0 is used as well as a recent PnP.PowerShell 2.2.59-nightly.

According to the blog post https://mortenknudsen.net/?p=2631, the old Microsoft.Graph.Core version 1.25.1.0 seems to originate from the module dependencies of PnP.PowerShell.

Expected behavior

Get-MgGroup should return the group objects of the tenants.

Actual behavior

DEBUG: [CmdletBeginProcessing]: - Get-MgGroup begin processing with parameterSet 'List'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process', AppName: 'dsc-group-lifecycle'.
DEBUG: [Authentication]: - Scopes: [AccessReview.ReadWrite.All, Group.ReadWrite.All, User.Read.All, Mail.Send].
DEBUG: [CmdletException]: Received exception with message 'TypeLoadException - Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. :    at Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient()
   at Microsoft.Graph.PowerShell.Module.BeforeCreatePipeline(InvocationInfo invocationInfo, HttpPipeline& pipeline)
   at Microsoft.Graph.PowerShell.Module.CreatePipeline(InvocationInfo invocationInfo, String parameterSetName)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgGroup_List.ProcessRecordAsync()'
Get-MgGroup_List: Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
DEBUG: [CmdletEndProcessing]: - Get-MgGroup end processing.

Steps to reproduce behavior

Minimal code example to reproduce the issue:

Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Groups
Import-Module PnP.PowerShell

# Connect to Microsoft Graph and SharePoint via client id + certificate
Connect-MgGraph -TenantId $tenantId -ClientId $clientId -CertificateThumbprint $certificateThumbprint
Connect-PnPOnline -Url $url -Tenant $tenant -ClientId $clientId -Thumbprint $certificateThumbprint

# Get groups (this is the command that will fail)
$groups = Get-MgGroup -All

What is the version of the Cmdlet module you are running?

The following module versions are installed exactly like that both locally under Windows and in the Azure automation account:

Version Name
2.2.59-nightly PnP.PowerShell
2.4.0 Microsoft.Graph.Authentication
2.4.0 Microsoft.Graph.Groups
2.4.0 Microsoft.Graph.User

The nighly version of PnP.PowerShell has been installed by intention since there were known issues regarding module conflicts with Az.* and others in the last weeks, which should have been fixed in latest nightly versions.

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : Azure Automation runbooks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

@veronicageek This bug is clearly not solved, and the cause is not a MSGraph module. As mentioned by duschu the outdated Microsoft.Graph.Core.dll from PnP.PowerShell is the cause. Please reopen the issue.

image

A workaround is to delete the outdated DLL from the PnP.PowerShell location (until the next PnP module update). Then the Graph request is working. Graph loads the correct version.

image

I’m having the same issues with scripts that require to use Graph and PnP. Deleting Microsoft.Graph.Core.dll from the PnP module works for me. However, I’m concerned that the PnP module might encounter unforeseen problems. It would be very nice to resolve this long standing issue. Graph has been updating their module quite regularly. IMHO, keeping such a old version of their DLL in the PnP module will just become increasingly problematic.

I have this issue as well. Manually deleting Microsoft.Graph.Core from PnP module install directory fixed my Graph issues. Not a great workaround but works.

How I can do this in a runbook?

Hi @gautamdsheth

Can we reopen this issue? Because it is still not working and pnp loading the wrong msgraph core dll