Skip to content
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

[BUG] Assembly Conflicts with Microsoft.Graph Module #3637

Open
5 tasks
cprovpo opened this issue Dec 15, 2023 · 57 comments
Open
5 tasks

[BUG] Assembly Conflicts with Microsoft.Graph Module #3637

cprovpo opened this issue Dec 15, 2023 · 57 comments
Labels
bug Something isn't working

Comments

@cprovpo
Copy link

cprovpo commented Dec 15, 2023

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 cprovpo added the bug Something isn't working label Dec 15, 2023
@JNichNP
Copy link

JNichNP commented Dec 20, 2023

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.

@Jaffa666
Copy link

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.

@cprovpo
Copy link
Author

cprovpo commented Dec 26, 2023

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
Copy link
Author

cprovpo commented Jan 12, 2024

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
Copy link
Author

cprovpo commented Jan 12, 2024

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!

@fasteiner
Copy link

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'.

@gkDoSt
Copy link

gkDoSt commented Feb 8, 2024

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

@MichaMican
Copy link

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

@HeKr09
Copy link

HeKr09 commented Feb 19, 2024

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

@rvanandel-hcg
Copy link

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.

@crnnr
Copy link

crnnr commented Feb 21, 2024

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

@jdarre
Copy link

jdarre commented Feb 23, 2024

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.

@Legitage
Copy link

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.

@cyrilchotard
Copy link

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

@kpinel
Copy link

kpinel commented Mar 6, 2024

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 user@domain.com

DisplayName Id          Mail               UserPrincipalName
----------- --          ----               -----------------
DigitalUser User-GUID   user@domain.com    user@domain.com

PS > Import-Module PnP.PowerShell
PS > get-mguser -UserId user@domain.com

DisplayName Id          Mail               UserPrincipalName
----------- --          ----               -----------------
DigitalUser User-GUID   user@domain.com    user@domain.com

PS > connect-pnpOnline -Url tenant.sharepoint.com -Interactive
PS > get-mguser -UserId user@domain.com

DisplayName Id                                   Mail               UserPrincipalName
----------- --                                   ----               -----------------
DigitalUser User-GUID                            user@domain.com    user@domain.com

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.

@jdenka
Copy link

jdenka commented Mar 14, 2024

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.

@kpinel
Copy link

kpinel commented Mar 16, 2024 via email

@dennis
Copy link

dennis commented Mar 16, 2024

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

@jdenka
Copy link

jdenka commented Mar 23, 2024

@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.

@cornettew
Copy link
Contributor

+1

@jgriff500
Copy link

This is so stinking frustrating.....

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

@jgriff500
Copy link

@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.

@kpinel
Copy link

kpinel commented Apr 13, 2024 via email

@jgriff500
Copy link

@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.

@TobiasAT
Copy link

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.

@SDooof
Copy link

SDooof commented Apr 16, 2024

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!

@Rwarcards762
Copy link

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 -- huge props for this. Great workaround. Thank you!!

@Roladin
Copy link

Roladin commented May 24, 2024

We also have this issue.

In my test environment I can confirm this combination of modules will fail with the error below.

Azure Automation PS 7.2 Runtime Environment modules. This is a custom runtime environment.
Az 11.2.0
Azure CLI 2.56.0
Microsoft.Graph.Authentication 2.19.0
Microsoft.Graph.Identity.SignIns 2.19.0
Microsoft.Graph.Users.Actions 2.19.0
PnP.PowerShell 2.4.0

Runbook output:
Get-MgIdentityConditionalAccessPolicy_List: Line | 36 | $CAPs = Get-MgIdentityConditionalAccessPolicy | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

It doesn't matter what order modules are loaded in the runbook.

In an older AA environment we have, the system-generated runtime environments are different and luckily the 7.2 runtime has the old 1.25.0 graph module still in it along with pnp 2.x.0 (hopefully I remembered this accurately, system-generated runtimes give the version simply as "Custom" with a date and size. All modules are from a year ago); automations here still work for the moment. Still, they are using old versions which is not ideal long-term.

I don't want to compromise on security by having runbooks run on-prem on self-hosted runners if they don't need to touch on-prem resources. If I did this, I would have to use cert-based app reg auth and a non-standard pnp module which may cause other issues down the line.
Much more preferable for Azure Automation runbooks is using the latest versions of graph and pnp directly from PSGallery along with the security of using Azure Managed Identities for API access as we currently do when possible.

In Azure Automation runtime environments, it may be a case of uploading a custom version of the pnp module with the offending Microsoft.Graph.Core files removed as per the workaround from @TobiasAT (great writeup, thanks mate). I haven't tested this and runtime environments are still in preview so implementation could change.

Keen to hear any updates/experiences in AA for this issue.

Thank you

@HeKr09
Copy link

HeKr09 commented May 24, 2024

@TobiasAT
Although it was a big help, I encountered an issue after running the script.

Get-PnPSiteTemplate: D:\TFS\SWO.PortalServices\Customer Creation\Export-SwoPortalTemplate.ps1:161
Line |
 161 |      Get-PnPSiteTemplate -Out $fullPath -Schema LATEST -Encoding ([Sys|      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 file or assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file
     | specified.
Write-Error: XML does not exist. Error during site template export.

I really don't know what the problem is to update the dll within PnP...

@nicole-ge
Copy link

We also have this issue.

In my test environment I can confirm this combination of modules will fail with the error below.

Azure Automation PS 7.2 Runtime Environment modules. This is a custom runtime environment.
Az 11.2.0
Azure CLI 2.56.0
Microsoft.Graph.Authentication 2.19.0
Microsoft.Graph.Identity.SignIns 2.19.0
Microsoft.Graph.Users.Actions 2.19.0
PnP.PowerShell 2.4.0

Runbook output:
Get-MgIdentityConditionalAccessPolicy_List: Line | 36 | $CAPs = Get-MgIdentityConditionalAccessPolicy | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

It doesn't matter what order modules are loaded in the runbook.

In an older AA environment we have, the system-generated runtime environments are different and luckily the 7.2 runtime has the old 1.25.0 graph module still in it along with pnp 2.x.0 (hopefully I remembered this accurately, system-generated runtimes give the version simply as "Custom" with a date and size. All modules are from a year ago); automations here still work for the moment. Still, they are using old versions which is not ideal long-term.

I don't want to compromise on security by having runbooks run on-prem on self-hosted runners if they don't need to touch on-prem resources. If I did this, I would have to use cert-based app reg auth and a non-standard pnp module which may cause other issues down the line.
Much more preferable for Azure Automation runbooks is using the latest versions of graph and pnp directly from PSGallery along with the security of using Azure Managed Identities for API access as we currently do when possible.

In Azure Automation runtime environments, it may be a case of uploading a custom version of the pnp module with the offending Microsoft.Graph.Core files removed as per the workaround from @TobiasAT (great writeup, thanks mate). I haven't tested this and runtime environments are still in preview so implementation could change.

Keen to hear any updates/experiences in AA for this issue.

Thank you

@Roladin
You can call the MS Graph via RestAPI. So you dont need to load the module

@HeKr09
Copy link

HeKr09 commented May 24, 2024

@TobiasAT Although it was a big help, I encountered an issue after running the script.

Get-PnPSiteTemplate: D:\TFS\SWO.PortalServices\Customer Creation\Export-SwoPortalTemplate.ps1:161
Line |
 161 |      Get-PnPSiteTemplate -Out $fullPath -Schema LATEST -Encoding ([Sys|      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 file or assembly 'Microsoft.Graph.Core, Version=1.25.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file
     | specified.
Write-Error: XML does not exist. Error during site template export.

I really don't know what the problem is to update the dll within PnP...

The same with Invoke-PnPSiteTemplate

@gkDoSt
Copy link

gkDoSt commented May 27, 2024

Unfortunately, I can confirm @HeKr09 issue with the Invoke-PnPSiteTemplate cmdlet...
Is there already a timetable for the whole issue if and when the whole problem will be fixed?
Unfortunately, this issue has been open since december last year without any results.

@Roladin
Copy link

Roladin commented May 27, 2024

@nicole-ge thanks, good point. MS Graph REST API with PnP is a decent option at the moment for Azure Automation. If my weird system-generated runtime environment breaks I might have to go down that path :)

@Roladin
Copy link

Roladin commented Jun 10, 2024

Anyone from the PnP team available to comment on this issue?

@BlackC0ffee
Copy link

I can confirm this bug. :(

@rmangini
Copy link

Just to reiterate, this is EXTREMELY ANNOYING. Please PNP team.

@MichaMican
Copy link

MichaMican commented Jun 18, 2024

I guess they could port it to use Assembly Load Context (ALC) but that would require a TON of porting work. I am not even sure if there is a proper different way - because without ALC you will always conflict with some Versions of other Modules that target a different Dependency Version...

And as this is a non official/Open Source module i don't even know if it's realistic to hope that this will be implmented someday :/

@devops-fan
Copy link

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 so much Tobias! I had the same problem using MS Graph module and PnP in same script, but now fixed with your resolution!

@TobiasAT
Copy link

TobiasAT commented Jun 30, 2024

PnP.PowerShell module has been updated to version 2.5 last Thursday.

I checked known conflicts with the updated module.

  • Microsoft.Graph.Core.dll is still on version 1.25.x, no fix for that issue with the 2.5 module update. Still the conflict with the Microsoft Graph Authentication module.
  • Microsoft.Identity.Client.dll was updated to 4.61.3.0. The issues with the outdated 4.50.x.x (or lower) versions should be fixed.

@TobiasAT
Copy link

@HeKr09 For your case, or if the command requires the Microsoft.Graph.Core.dll from PnP.PowerShell module, you may have to split your script into two separate processes. One process uses just the Microsoft.Graph.Core.dll from PnP.PowerShell module, the other the updated Microsoft.Graph.Core.dll version.

If you mix the different versions of Microsoft.Graph.Core.dll in one process, the script will have conflicts again.

@vnerdahl
Copy link

I had a conflict between the powershell Graph and ExchangeOnline modules. I downgraded the ExchangeOnline to version 3.4.0 and it resolved the conflict.

@kpinel
Copy link

kpinel commented Jul 10, 2024

@vnerdahl What version of Graph are you using? I'm not having any issues using EXO 3.5.0 and Graph 2.19.0 together

@vnerdahl
Copy link

@vnerdahl What version of Graph are you using? I'm not having any issues using EXO 3.5.0 and Graph 2.19.0 together
I was having a conflict with Microsoft.Graph 2.19.0 and ExchangeOnlineManagement 3.5.0.

@akbazuka
Copy link

akbazuka commented Jul 18, 2024

For anyone looking for a workaround to use the PnP module and the Graph module in the same script, one way is to start a separate job within a script that encapsulates the import of one of the modules and run any of that module's cmdlets within it. For example, in the case where most of your logic lies on GraphAPI side, but you want to first get some sites from SharePoint, you can try the following solution:

$pnpJob = Start-Job -ScriptBlock {
    Import-Module PnP.PowerShell
    
    #Get all sites using PnP
    $tenantUrl = "https://tenant-admin.sharepoint.com"
    Connect-PnPOnline -Url $tenantUrl 
    
    $allSites = Get-PnPTenantSite
    return $allSites
}

#Run PnP operations in a separate job
$allSites = Receive-Job -Job $pnpJob -Wait
Remove-Job -Job $pnpJob

#Connect to MS Graph
Connect-MgGraph

#Rest of graph logic... E.g.

$allSites | ForEach-Object {
    Get-MgSite -Search $_.Url
}

@matthiashaldimann
Copy link

Thank you for the good workaround. It is very suitable for some cases, rather difficult to implement in others.
Is there a reason why PnP.PowerShell does not come with an up-to-date Microsoft.Graph.Core.dll or - even better - use the "original" Graph module instead of providing it's own copy of Graph SDK components?

@cythrault
Copy link

My workaround is to delete Microsoft.Graph.Core*.dll from the PnP module which is easy on a PC/Server. Not so much in automations.

@sabey2000
Copy link

sabey2000 commented Sep 27, 2024

You cannot handle too much the modules if you use the requirements.psd1 file unless you download both module in the modules folder and upload it with your zip file, which is not nice.

What I did so far, is that I always connect to mgraph prior to connect to pnp-online.

Connect-MgGraph -ManagedIdentity -NoWelcome
$PnPAdminConnection = Connect-PnPOnline -Url https://xxxxxx-admin.sharepoint.com -ManagedIdentity -ReturnConnection
$PnPSiteConnection = Connect-PnPOnline -Url $site -ManagedIdentity -ReturnConnection

This way, the right assembly is loaded. I did that for all my scripts in my Azure functions that are in the webapp.

I agree with @veronicageek , managing the assembly dependency is a nightmare between Az/Graph/PnP

@robertcaretta
Copy link

robertcaretta commented Sep 30, 2024

I am also facing this issue with PnP 2.12.10 and latest Mg modules.

@nicole-ge
Copy link

Hi @sabey2000

Does your example also work within Azure Automation Runbook?

@sabey2000
Copy link

Hi @sabey2000

Does your example also work within Azure Automation Runbook?

Yes, you have to connect to Microsoft Graph prior doing anything. This will force the assembly to load and PnP will use it. The opposite will not work. The issue with Azure Automation Runbook and Azure Function is that the powershell runtime is not restarted for each call. You run in the same powershell. So if a script connect to PnP and later another wants to connect to Graph it will fail.

@Nitesh058Raj
Copy link

Hello everyone, I had the same issue, and I used multiple stable versions of PnP and MS graph.
In my case, I was getting the error because, I was using Visual Studio code with PowerShell extension.

To resolve the issue,

  • use 'Connect-MgGraph' first at the top of the script then use the 'Connect-PnPOnline'
  • run the script on normal PowerShell terminal in visual studio code

[with pnp and MS graph latest versions]

I was facing the issue because, the env var in PowerShell extension: 'PSExecutionPolicyPreference Bypass'

The problem resolves for me with this approach, this might not work for you

@darrenw-npi
Copy link

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.

You sir, are a legend! I have been fighting this issue for days and couldn't get it working whatever order I used PnP and Graph in. Thank you so much for writing this and sharing it 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests