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] Microsoft.Graph and PnP.PowerShell conflict (Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider') #2285 #3395

Closed
2 of 6 tasks
duschu opened this issue Sep 4, 2023 · 20 comments
Labels
bug Something isn't working

Comments

@duschu
Copy link

duschu commented Sep 4, 2023

Notice

I have also reported this issue in the Microsoft.Graph repository (microsoftgraph/msgraph-sdk-powershell#2285), but I would be really happy if you could also investigate the error from this side. Thank you.

Reporting an Issue or Missing Feature

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.

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.

According to the blog post https://mortenknudsen.net/?p=2631, the old Microsoft.Graph.Core version 1.25.1.0 seems to originate from the module dependencies of PnP.PowerShell.

Expected behavior

Get-MgGroup should return the group objects of the tenants.

Actual behavior

DEBUG: [CmdletBeginProcessing]: - Get-MgGroup begin processing with parameterSet 'List'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process', AppName: 'dsc-group-lifecycle'.
DEBUG: [Authentication]: - Scopes: [AccessReview.ReadWrite.All, Group.ReadWrite.All, User.Read.All, Mail.Send].
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.GetMgGroup_List.ProcessRecordAsync()'
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'.
DEBUG: [CmdletEndProcessing]: - Get-MgGroup end processing.

Steps to reproduce behavior

Minimal code example to reproduce the issue:

Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Groups
Import-Module PnP.PowerShell

# Connect to Microsoft Graph and SharePoint via client id + certificate
Connect-MgGraph -TenantId $tenantId -ClientId $clientId -CertificateThumbprint $certificateThumbprint
Connect-PnPOnline -Url $url -Tenant $tenant -ClientId $clientId -Thumbprint $certificateThumbprint

# Get groups (this is the command that will fail)
$groups = Get-MgGroup -All

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

The following module versions are installed exactly like that both locally under Windows and in the Azure automation account:

Version Name
2.2.59-nightly PnP.PowerShell
2.4.0 Microsoft.Graph.Authentication
2.4.0 Microsoft.Graph.Groups
2.4.0 Microsoft.Graph.User

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.

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

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : Azure Automation runbooks
@duschu duschu added the bug Something isn't working label Sep 4, 2023
@duschu
Copy link
Author

duschu commented Sep 6, 2023

Is it possible that you can upgrade the Microsoft.Graph.Core.dll dependency in your module to v3.x according to the comment microsoftgraph/msgraph-sdk-powershell#2285 (comment) by @peombwa? Thank you for any feedback and further help.

@taraldjoh
Copy link

Is it possible that you can upgrade the Microsoft.Graph.Core.dll dependency in your module to v3.x according to the comment microsoftgraph/msgraph-sdk-powershell#2285 (comment) by @peombwa? Thank you for any feedback and further help.

Bumping this one as i'm experiencing issues because of this as well.
Hope this can be resolved fairly quickly. Help & feedback would be greatly appreciated!

@veronicageek
Copy link
Collaborator

@duschu - We have no control over the MSGraph module (or Az module). They may be updating / upgrading their dependencies later on, and we can only suggest running the PnP cmdlets in a different thread. If the PnP cmdlets work on their own, there's unfortunately nothing we can do.

@jwiersem
Copy link

What is the real solution or a good workaround for this? @veronicageek? Running into this error in Azure automation.

@jwiersem
Copy link

Errr, apparently this method exists: https://pnp.github.io/powershell/cmdlets/Invoke-PnPGraphMethod.html :D

@martinb3sharp
Copy link

I worked around this issue by forcing PowerShell to load specific versions of the modules. I hit the issue with an Azure Function and put this in the requirements.psd1:

@{
    'Microsoft.Graph.Authentication' = '2.2.0'
    'Microsoft.Graph.Identity.Governance' = '2.2.0'
    'Microsoft.Graph.Users' = '2.2.0'
    'PNP.PowerShell' = '2.2.0'
    'Az.Accounts'  = '1.8.0'
    'Az.Resources' = '2.0.1'
    'Az.KeyVault' = '4.3.1'
}

You will be able to do a similar thing for the Azure Automation account, by making sure the module versions installed in the account are the ones that do not conflict.

@danmyhre
Copy link

danmyhre commented Feb 6, 2024

@veronicageek Can you reopen this? This issue is not resolved.

@TobiasAT
Copy link

TobiasAT commented Feb 7, 2024

@veronicageek This bug is clearly not solved, and the cause is not a MSGraph module. As mentioned by duschu the outdated Microsoft.Graph.Core.dll from PnP.PowerShell is the cause. Please reopen the issue.

image

A workaround is to delete the outdated DLL from the PnP.PowerShell location (until the next PnP module update). Then the Graph request is working. Graph loads the correct version.

image

@danmyhre
Copy link

danmyhre commented Feb 7, 2024

This is from a fresh install...it is using a version from 2021

image

@YuriySamorodov
Copy link
Contributor

Hey, @danmyhre . I would probably open another issue for this...

@bnalley
Copy link

bnalley commented Apr 12, 2024

I have this issue as well. Manually deleting Microsoft.Graph.Core from PnP module install directory fixed my Graph issues. Not a great workaround but works.

@nicole-ge
Copy link

Hi @gautamdsheth

Can we reopen this issue? Because it is still not working and pnp loading the wrong msgraph core dll

@nicole-ge
Copy link

I have this issue as well. Manually deleting Microsoft.Graph.Core from PnP module install directory fixed my Graph issues. Not a great workaround but works.

How I can do this in a runbook?

@DavidHorsky
Copy link

I have this issue as well. Manually deleting Microsoft.Graph.Core from PnP module install directory fixed my Graph issues. Not a great workaround but works.

How I can do this in a runbook?

I have a workaround for the Azure Automation Runbook.
Use a Graph cmdlet before connecting to PnP. Something basic like Get-MgGroup works just fine. All other cmdlets work after that, even after connecting to PnP.
Don't know if the graph action has to succeed, haven't tested that. But for my case it works.

@cythrault
Copy link

I'm having the same issues with scripts that require to use Graph and PnP. Deleting Microsoft.Graph.Core.dll from the PnP module works for me. However, I'm concerned that the PnP module might encounter unforeseen problems. It would be very nice to resolve this long standing issue. Graph has been updating their module quite regularly. IMHO, keeping such a old version of their DLL in the PnP module will just become increasingly problematic.

@dobbij88
Copy link

So this issue got marked as closed without ever actually being resolved? I'm still having this issue in September of '24 with the latest PnP modules in an Azure Automation Runbook.

@sabey2000
Copy link

This is still an issue causing a lot of nightmare for us with Azure Function CI/CD pipeline and the maintenance of the requirement.ps1 file. It still an issue with

'Microsoft.Graph' = '2.23.0'
'PnP.PowerShell' = '2.10.0'

@veronicageek , is it possible to reopen and investigation this issue?

@sabey2000
Copy link

Ok, I better understand the problem now that I'm able to simulate the situation on my own machine.

First, I have the problem with I'm using a lot of powershell script in Azure function web app so they all share the same assembly context so conflit occur if script 1 use PnP-Online and than script 2 use the Connect-MgGraph.

Nothing I can do, it's by design and limitation, hard to resolve : https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.4

So the trick, is like it was written in a previous post, you have to Connect-MgGraph before doing a PnP-Online even if the script does not required access to graph. This is a workaround but the real solution is to resolve the dependency requirement.

@duschu
Copy link
Author

duschu commented Sep 27, 2024

@veronicageek Hi, can you please re-open my issue report because the topic is still not solved on the side of the PnP module as you can see from the recent comments. Thank you

@veronicageek
Copy link
Collaborator

@duschu - There's an open issue #3637 with a longer thread and possible workaround(s). Every module (MSFT, PnP, or else) being compatible with each other is an endless battle and would be more complex to solve (if at all possible) than people think.

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