-
Notifications
You must be signed in to change notification settings - Fork 188
Microsoft.Graph and PnP.PowerShell conflict (Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider') #2285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have the same issue and it happens often. |
The issue here is with the version of
Please transfer the issue to the PnP.PowerShell repo as they'll need to update the dll in their module. As a workaround, you can update your script to ensure that Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Groups
...
$groups = Get-MgGroup -All # Before PnP.Powershell import.
...
Import-Module PnP.PowerShell |
Thank you, @peombwa, I'm waiting for the response regarding the issue pnp/powershell#3395 in the PnP.PowerShell repo. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
The workaround does work, but it's not really an issue that is unique for PnP.PowerShell module, as I get the exact same issue when using Az! If you connect to both Az and MgGraph and call Get-AzADUser before calling Get-MgUser you also receive the exact same error. I actually posted about this in pnp.powershell a year ago, and they did a great job in implementing my suggestion of using the ALC bridging pattern, which got rid of most of the colliding assembly issues. If you are not familiar with it, ALC is the new way of loading assemblies in PowerShell 7, and have a better way of handling multiple versions of the same assembly, and as I understand it, is the "preferred" way of loading assemblies in PowerShell 7 modules in general. So if all module developers use this approach, we wouldn't see most of these conflicts :-) [https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.3#loading-through-net-core-assembly-load-contexts](Loading through .NET Core Assembly Load Contexts) |
Hello, |
I experience the same issue. Was a solution ever found? |
@joostvdlinden |
I was able to determine that there is an issue with the latest version of Microsoft.Graph PowerShell (v 2.26.1). Link: https://office365itpros.com/2025/03/04/powershell-sdk-problems/ Additionally, I had to:
In that specific order within my Azure Automation Runbook. Make sure that Microsoft Graph performs a random action before it is connecting with PnP (source link: #2622). At least it works now for me. |
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:
Expected behavior
Get-MgGroup should return the group objects of the tenants.
Debug Output
Module Versions
The following module versions are installed exactly like that both locally under Windows and in the Azure automation account:
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:
The text was updated successfully, but these errors were encountered: