Invoke-MgGraphRequest with error “Microsoft.Graph.Core, Version=1.25.1.0”

I regularly use the PowerShell modules PnP.PowerShell and Microsoft.Graph.Authentication in combination with a script. Depending on when the module for PnP.PowerShell is loaded, PowerShell 7 shows the following error for Invoke-MgGraphRequest. The issue can also occur with all Microsoft Graph modules.

Could not load type ‘Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider’ from assembly ‘Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

PowerShell

A Google search quickly finds a good description of the cause on GitHub

The issue here is with the version of Microsoft.Graph.Core that’s loaded by the PnP.PowerShell module. The module loads an outdated version of Microsoft.Graph.Core, Version=1.25.1.0 dll – https://www.nuget.org/packages/Microsoft.Graph.Core/1.25.0. The latest version of Microsoft.Graph.Core is 3.x, which is what Microsoft.Graph PowerShell SDK uses.

A check confirms the case, PnP.PowerShell loads the outdated DLL from Microsoft.Graph.Core.

PowerShell
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location | where FullName -Like "Microsoft.Graph.Core*"

I can’t load the PnP.PowerShell module at a different location in the script for my task.
The creator of the issue has opened a new issue in the PnP repository. Unfortunately, the issue was closed by a PnP team member with a false justification and has not yet been reopened. Another issue 3735 was created.

GitHub

The Microsoft.Graph.Authentication module is not the cause.
I also tested the case with the latest nightly version (2.3.49-nightly) of PnP.PowerShell. The outdated DLL in the PnP.PowerShell module has not yet been replaced.

A workaround is to delete the outdated Microsoft.Graph.Core.dll file from the PnP.PowerShell module directory. It is a workaround. The file will be created again the next time the module is updated.

  1. Close all open PowerShell instances (Visual Studio Code included). The DLL must not be loaded.
  2. You can delete the file manually via Windows Explorer or via a new PowerShell instance.
PowerShell
$PnPModuleDirectory = (Get-Module PnP.PowerShell -ListAvailable)[0].ModuleBase
Remove-Item -Path ($PnPModuleDirectory + "\Core\Microsoft.Graph.Core.dll") -Force


If Invoke-MgGraphRequest is executed again the Microsoft.Graph.Authentication module loads the correct DLL (instead of PnP.PowerShell) and the query works without errors.

Share
Avatar photo

Tobias Asböck

Tobias is a Senior System Engineer with around ten years of professional experience with Microsoft 365 products such as SharePoint Online, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. Tobias is a PowerShell Scripter with certifications for Microsoft 365 products. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities.

Leave a Reply

Your email address will not be published. Required fields are marked *