powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Assembly Conflicts with Microsoft.Graph Module

Open cprovpo opened this issue 1 year ago • 63 comments

Reporting an Issue or Missing Feature

Running Microsoft.Graph cmdlets, such as Connect-MgGraph and Get-MgApplication, produce an assembly conflict error if run after PnP.PowerShell assemblies have already been loaded.

Expected behavior

According to release notes for PnP.PowerShell 2.3.0, assembly conflicts have been resolved. With this being true, I was hopeful I could develop a script that used cmdlets from both PnP.PowerShell and Microsoft.Graph. In my scenario, this doesn't appear to be the case.

Actual behavior

Results from trying to run Connect-MgGraph and Get-MgApplication after PnP had already been loaded: image

Output of assemblies loaded in the session. The two assemblies called out in the MgGraph exception are sourced from the PnP.PowerShell Module image

Steps to reproduce behavior

Import-Module PnP.PowerShell
Connect-PnPOnline -Url $url -Interactive
Disconnect-PnPOnline
Import-Module Microsoft.Graph
Connect-MgGraph
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential
Get-MgApplication
Disconnect-MgGraph

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

PnP.Powershell - 2.3.3 Nightly Build Microsoft.Graph.Authentication - 2.9.0 Microsoft.Graph.Applications - 2.9.0

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

  • [x ] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

cprovpo avatar Dec 15 '23 19:12 cprovpo

I fixed this by grabbing the Microsoft.Graph.Core.dll from Microsoft.Graph.Authentication and dropping it right into C:\Program Files\PowerShell\Modules\PnP.PowerShell\2.3.8\Core

Not the best, nor the most elegant solution, but it worked.

JNichNP avatar Dec 20 '23 17:12 JNichNP

I fixed this by grabbing the Microsoft.Graph.Core.dll from Microsoft.Graph.Authentication and dropping it right into C:\Program Files\PowerShell\Modules\PnP.PowerShell\2.3.8\Core

Not the best, nor the most elegant solution, but it worked.

Also grab the Microsoft.Identity.Client.dll from Microsoft.Graph.Authentication and replace the PnP version. This resolved Connect-MGGRAPH error trying to use the older dll files from the PnP module if it was called first.

Jaffa666 avatar Dec 21 '23 18:12 Jaffa666

Thanks for the suggested workarounds - I'll be sure to test those. I am concerned about the lengthy regression testing that might be required by replacing these, as I'm not sure if the replaced DLLs will cause issues with the rest of my code.

cprovpo avatar Dec 26 '23 21:12 cprovpo

As an update to my previous post, I have tried the DLL replacements as indicated above. While this resolves the authentication issue, calling other Graph cmdlets (such as Get-MgUser) reveals other assembly conflicts

Get-MgUser_List: Method not found: 'Void Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[], Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'.

Unfortunately, we are at a crossroads in getting utility out of both PnP.PowerShell and Microsoft.Graph.

cprovpo avatar Jan 12 '24 19:01 cprovpo

One final update - I think I may have found a valuable workaround tool, and it's built in:

Invoke-PnPGraphMethod

I was just able to pull Users and Applications from Graph API without any assembly conflicts. I did not know this cmdlet exists, but it seems like an excellent workaround. A quick sample of a couple commands I ran

$users = Invoke-PnPGraphMethod -Url "/users"
$applications = Invoke-PnPGraphMethod -Url "/applications"

Hopefully this helps someone else!

cprovpo avatar Jan 12 '24 20:01 cprovpo

The issue persists with the new version of graph (2.12.0) and PNP 2.3.0, could you please fix this issue? otherwise people are forced to work with the old PNP version 1.12.0.

Error Message when connecting to graph, after connecting to PNP: ERROR - Connect to Microsoft Graph failed.(TenantId: tttech365.onmicrosoft.com, AppId ****) ERROR - Connect-MgGraph: Line | 135 | Connect-MgGraph -TenantId $AzureTenant -ClientId $AppId - … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ClientCertificateCredential authentication failed: Could not load type 'Microsoft.Identity.Client.BaseAbstractApplicationBuilder`1' from assembly 'Microsoft.Identity.Client, Version=4.50.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'.

fasteiner avatar Jan 18 '24 14:01 fasteiner

Any updates on this? Im facing the same issue :/

gkDoSt avatar Feb 08 '24 13:02 gkDoSt

Same issue here. Absolutely horrible bug tbh. This is currently a hard blocker for us as for security and regularoty reasons we may not tamper with module files of modules, hence we can't work with the workarround by @JNichNP

MichaMican avatar Feb 08 '24 13:02 MichaMican

Is there anything new? This is a really annoying bug.

HeKr09 avatar Feb 19 '24 05:02 HeKr09

Add me to the list of people who are experiencing this issue. Brand new server with the lastest versions of PNP and Graph modules. There's gotta be a way to fix this. Seems both Graph and PNP teams are blaming the other team rather than coming up with a solution.

rvanandel-hcg avatar Feb 19 '24 17:02 rvanandel-hcg

Is there a timeline for this? Also facing this issue with workaround not feasible :///

crnnr avatar Feb 21 '24 07:02 crnnr

Any update here? As of now, we have to run a single server with PnP.Powershell 2.3.0 and version 1.28 of the Mg-Module.

jdarre avatar Feb 23 '24 13:02 jdarre

Our automation scripts are also failing with the same error and for the same reason. Another short-term (not ideal) workaround for using PnP 2.3 is to uninstall the MS Graph module and/or install Microsoft.Graph 2.8.

This DLL version conflict needs to be resolved in way that it doesn't keep happening every few updates.

Legitage avatar Feb 25 '24 09:02 Legitage

Same issue for me in Azure Automation with PnP.PowerShell 2.4.0 and Microsoft.Graph 2.15.0

cyrilchotard avatar Mar 04 '24 17:03 cyrilchotard

A method that worked for me was to connect to Graph, make a call and then connect to PnP.

This is the quick test that I did and have been using the same session for PnP and Graph calls.

PowerShell 7.4.1
PS > connect-mgGraph -TenantId GUID -NoWelcome
PS > get-mguser -UserId [email protected]

DisplayName Id          Mail               UserPrincipalName
----------- --          ----               -----------------
DigitalUser User-GUID   [email protected]    [email protected]

PS > Import-Module PnP.PowerShell
PS > get-mguser -UserId [email protected]

DisplayName Id          Mail               UserPrincipalName
----------- --          ----               -----------------
DigitalUser User-GUID   [email protected]    [email protected]

PS > connect-pnpOnline -Url tenant.sharepoint.com -Interactive
PS > get-mguser -UserId [email protected]

DisplayName Id                                   Mail               UserPrincipalName
----------- --                                   ----               -----------------
DigitalUser User-GUID                            [email protected]    [email protected]

PS > Get-PnPTenantSite -Url https://tenant.sharepoint.com/teams/msteams_50e441

Url                                                       Template LocaleId
---                                                       -------- --------
https://tenant.sharepoint.com/teams/msteams_50e441        GROUP#0  1033

set-pnptenantSite -Url https://tenant.sharepoint.com/teams/ACA_TM_SSTALeadershipGroup-LwpsJ -LockState unlock
WARNING: You changed the lockstate of a site. This change is not guaranteed to be effective immediately. Please wait a few minutes for this to take effect.
PS > set-pnptenantSite -Url https://tenant.sharepoint.com/teams/ACA_TM_SSTALeadershipGroup-LwpsJ -LockState NoAccess
WARNING: You changed the lockstate of a site. This change is not guaranteed to be effective immediately. Please wait a few minutes for this to take effect.

kpinel avatar Mar 06 '24 22:03 kpinel

Facing same issues here, my workflow is that I get information from Sharepoint with PNP Powershell and then connecting to Graph, this is not working properly for obvious resons.

Seems like there are quite a few people that are facing the same issues here. Have tried to use some workarounds but have not got anything to work except to use really old versions of either Graph (1.25) or go back to PNP Powershell version 1.x.

That should not be the solution to this issue.

jdenka avatar Mar 14 '24 09:03 jdenka

@Dennis, My workaround is still working. I currently have a session open to SharePoint, Graph, and EXO and haven't had any issue. The main thing is that the Graph commands are executed first. Pnp then uses that token provider in preference to the one bundled with it.

Kind regards, Kevin

If you're going to be passionate about something, be passionate about learning

On Thu, 14 Mar 2024 at 19:46, Dennis Johansson @.***> wrote:

Facing same issues here, my workflow is that I get information from Sharepoint with PNP Powershell and then connecting to Graph, this is not working properly for obvious resons.

Seems like there are quite a few people that are facing the same issues here. Have tried to use some workarounds but have not got anything to work except to use really old versions of either Graph (1.25) or go back to PNP Powershell version 1.x.

That should not be the solution to this issue.

— Reply to this email directly, view it on GitHub https://github.com/pnp/powershell/issues/3637#issuecomment-1997043125, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGVVB6ZWTHV2UXQRTJ6FSLYYFWW5AVCNFSM6AAAAABAW5IDHOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJXGA2DGMJSGU . You are receiving this because you commented.Message ID: @.***>

kpinel avatar Mar 16 '24 13:03 kpinel

Keep in mind, that writing @ notifies that user of your message :)

dennis avatar Mar 16 '24 16:03 dennis

@dennis, My workaround is still working. I currently have a session open to SharePoint, Graph, and EXO and haven't had any issue. The main thing is that the Graph commands are executed first. Pnp then uses that token provider in preference to the one bundled with it. Kind regards, Kevin ------------------------------- If you're going to be passionate about something, be passionate about learning On Thu, 14 Mar 2024 at 19:46, Dennis Johansson @.> wrote: Facing same issues here, my workflow is that I get information from Sharepoint with PNP Powershell and then connecting to Graph, this is not working properly for obvious resons. Seems like there are quite a few people that are facing the same issues here. Have tried to use some workarounds but have not got anything to work except to use really old versions of either Graph (1.25) or go back to PNP Powershell version 1.x. That should not be the solution to this issue. — Reply to this email directly, view it on GitHub <#3637 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGVVB6ZWTHV2UXQRTJ6FSLYYFWW5AVCNFSM6AAAAABAW5IDHOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJXGA2DGMJSGU . You are receiving this because you commented.Message ID: @.>

The workflow i'm running does not support that since I have to go to SharePoint first and that breaks everything. This should not be a issue and should be fixed so both of the modules can be used and used in what order needed for the current workflow. It is a issue, that the PNP.PowerShell team needs to fix.

jdenka avatar Mar 23 '24 18:03 jdenka

+1

cornettew avatar Apr 12 '24 11:04 cornettew

This is so stinking frustrating.....

Someone please explain why "Connect-MgGraph" loads Pnp.Powershell assemblies?

jgriff500 avatar Apr 12 '24 19:04 jgriff500

@kpinel -- Are you using Visual Studio Code or running scripts from pwsh.exe?

If I have the Pnp.PowerShell module installed, I can't even Connect-MgGraph - I get the same error as the OP. If I uninstall Pnp.PowerShell my Connect-MgGraph works fine.

jgriff500 avatar Apr 12 '24 20:04 jgriff500

It doesn't matter. It's PowerShell regardless.

Also, graph doesn't load PNP assemblies. They both use the same assemblies. Graph happens to use the newer ones so if you connect to graph first, the PNP modules won't load the older assemblies included with it.

On Sat, 13 Apr 2024, 06:06 jgriff500, @.***> wrote:

@kpinel https://github.com/kpinel -- Are you using Visual Studio Code or running scripts from pwsh.exe?

If I have the Pnp.PowerShell module installed, I can't even Connect-MgGraph - I get the same error as the OP. If I uninstall Pnp.PowerShell my Connect-MgGraph works fine.

— Reply to this email directly, view it on GitHub https://github.com/pnp/powershell/issues/3637#issuecomment-2052452727, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGVVB3SR6GX6D4VNF2YUCTY5A5EHAVCNFSM6AAAAABAW5IDHOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJSGQ2TENZSG4 . You are receiving this because you were mentioned.Message ID: @.***>

kpinel avatar Apr 13 '24 04:04 kpinel

@kpinel my experience sounds slightly different.

From Visual Studio Code, Connect-MgGraph fails if PnP.PowerShell is installed (without importing or issuing any commands). I can do a fresh PS session, Connect-MgGraph and see there are Pnp.PowerShell assemblies loaded.

If I uninstall Pnp.PowerShell, Connect-MgGraph works perfectly.

I have a script that uses MgGraph and PnP.Powershell -- if I run from PS 7 (right click, open with PWSH), my experience mimics others -- run Connect-MgGraph first, run a Mg-Get command, THEN import PnP.Powershell.

jgriff500 avatar Apr 15 '24 20:04 jgriff500

I had the same issues and (for a workaround) wrote a PowerShell script to fix two known issues between the PnP.PowerShell and Microsoft.Graph.Authentication modules. If interested, read Resolve-TAPnPPowerShellConflicts in my repository.

TobiasAT avatar Apr 15 '24 21:04 TobiasAT

I had the same issues and (for a workaround) wrote a PowerShell script to fix two known issues between the PnP.PowerShell and Microsoft.Graph.Authentication modules. If interested, read Resolve-TAPnPPowerShellConflicts in my repository.

Thank you, this solved my pain and agony in trying to figure out a way to make both pnp and graph modules work in 1 script!

SDooof avatar Apr 16 '24 06:04 SDooof

Thank you @TobiasAT. This is a tremendous help.

jgriff500 avatar Apr 17 '24 13:04 jgriff500

Just bumped into this issue with a colleague and was immediately able to solve it using the workaround script from @TobiasAT. Thank you very much!

tschlienger avatar Apr 23 '24 13:04 tschlienger

Hi @gautamdsheth or @veronicageek

This Bug is still open and not working causa the pnp module is loading the wrong ms graph DLL. My azure automation failed .

Please help a lot of Bugs to this issues are reporter

Thank you in advance

nicole-ge avatar Apr 27 '24 00:04 nicole-ge

Seeing the same issue, my DEV VM is Windows 11 and has the following installed

PowerShell Version: 7.4.2 PnP PowerShell Version: 2.4.0 Microsoft.Graph Version: 2.18.0 Microsoft.Graph.Beta Version: 2.18.0 Microsoft.Identity.Client: 4.53.0

The error happens in the following line of code

$eid = get-mggroup -consistencylevel eventual -search $groupSearchTerm …

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

Consistently happens when I'm running the script via VS Code Terminal Window (Powershell 7.4.2 process) or from my Terminal Window (PowerShell 7.4.2).

I have tried TobiasAT's script (Above)

I had the same issues and (for a workaround) wrote a PowerShell script to fix two known issues between the PnP.PowerShell and Microsoft.Graph.Authentication modules. If interested, read Resolve-TAPnPPowerShellConflicts in my repository.

I get the following errors

     | Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.Graph.Core,
     | Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

     | Could not load type 'Microsoft.Graph.ICollectionPage`1' from assembly 'Microsoft.Graph.Core, Version=3.0.9.0,
     | Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not load type 'Microsoft.Graph.ICollectionPage`1' from
     | assembly 'Microsoft.Graph.Core, Version=3.0.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not
     | load type 'Microsoft.Graph.ICollectionPage`1' from assembly 'Microsoft.Graph.Core, Version=3.0.9.0,
     | Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not load type 'Microsoft.Graph.ICollectionPage`1' from
     | assembly 'Microsoft.Graph.Core, Version=3.0.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not
     | load type 'Microsoft.Graph.ICollectionPage`1' from assembly 'Microsoft.Graph.Core, Version=3.0.9.0,
     | Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

RobIreland68 avatar Apr 30 '24 22:04 RobIreland68