Skip to content

Microsoft.Graph and PnP.PowerShell conflict (Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider') #2285

Closed
@duschu

Description

@duschu

Describe the bug
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.

As stated in the details below, 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.

To Reproduce
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

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

Debug Output

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.

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

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

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. See links under "additional context" for further information.

Environment Data
Local Windows environment: PSVersion 7.3.6
Azure automation account and runbook with version PS 7.2

Additional context
The problem seems to be related to the following bug reports, but it did not help to solve my issue:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions