microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
695 stars 168 forks source link

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

Closed kpinel closed 7 months ago

kpinel commented 7 months ago

Describe the bug When loading the latest versions of PnP.PowerShell and Graph and running any Graph query, we get the following error Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core

To Reproduce Steps to reproduce the behavior:

  1. Import-module pnp.PowerShell
  2. Connect-mggraph
  3. Note error Connect-MgGraph: InteractiveBrowserCredential authentication failed: Could not load type 'Microsoft.Identity.Client.BaseAbstractApplicationBuilder'1' from assembly 'Microsoft.Identity.Client, Version=4.50.0.0, Culture=neutral, PublicKeyToken

Load graph first

  1. Connect-MgGraph
  2. Connect

Expected behavior Expect both modules to be able to work together

Debug Output

Get-MgUser -UserId user@domain.com -Debug
DEBUG: [CmdletBeginProcessing]: - Get-MgUser begin processing with parameterSet 'Get'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [Application.ReadWrite.All, AppRoleAssignment.ReadWrite.All, Directory.ReadWrite.All, Group.Read.All, Group.ReadWrite.All, MailboxSettings.Read, openid, Organization.Read.All, profile, Team.Create, Team.ReadBasic.All, TeamMember.ReadWrite.All, TeamsActivity.Read, User.Read, User.Read.All, User.ReadWrite.All, UserAuthenticationMethod.Read.All, UserAuthenticationMethod.ReadWrite.All, email].
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.GetMgUser_Get.ProcessRecordAsync()'
Get-MgUser_Get: 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-MgUser end processing.

Module Version

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     2.15.0                Microsoft.Graph.Authentication      Core,Desk {Connect-MgGraph, Disconnect-MgGraph, Get-MgContext, Invoke-MgGraphRequest…}
Manifest   2.4.0                 PnP.PowerShell                      {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPAvailableSiteClassification…}

Environment Data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional context Also reporting the same bug in PnP.PowerShell just in case

Workaround
Connect-MgGraph Perform graph command Connect-PnPOnline

Commands from both modules seem to work after this

timayabi2020 commented 7 months ago

Hi @kpinel thank you for identifying and logging this issue and also providing a work around. The reason you are having that error is because of a conflict in the Microsoft.Graph.Core assemblies loaded in your session. pnp.PowerShell is using an old version (1.25.1.0) while Microsoft.Graph.PowerShell is using a newer version (3.0.9). I would suggest that you log this issue here https://github.com/pnp/powershell/issues, requesting that team to update their Microsoft.Graph.Core version.

image
kpinel commented 7 months ago

As noted in my original post, I had also posted into pnp PowerShell. Closing this one and putting pressure on the PnP team

DarrenGowing commented 2 months ago

FYI, to resolve this I just deleted the Microsoft.Grap.Core.dll in the PNP module folder. All works now.

I am using modules: PnP.PowerShell 2.5.0 Microsoft.Graph 2.21.1

I have had similar issues in the past where one module was updated and the others weren't.