msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Version 2.18.0 broken - Method not found: error

Open marckean opened this issue 1 year ago • 11 comments

Describe the bug

I am running this:

if (-not(Get-Module -ListAvailable -Name Microsoft.Graph.Groups)) { Install-Module -Name Microsoft.Graph.Groups -Scope CurrentUser -AllowClobber -Force Import-Module -Name Microsoft.Graph.Groups }

Sign into the Microsoft Graph

$resource = "https://graph.microsoft.com" $token = (Get-AzAccessToken -TenantId $tenantID -ResourceUrl $resource).Token

Create a SecureString from the token

$SecureToken = ConvertTo-SecureString $token -AsPlainText -Force

Use the SecureString token to connect

Connect-MgGraph -AccessToken $SecureToken

But I get this error:

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

Expected behavior

I should get something like this:

Welcome to Microsoft Graph!

Connected via userprovidedaccesstoken access using c288694f-2e16-4c20-928d-c262d8008520

How to reproduce

It's due to the latest Microsoft.Graph.Groups module that's just been released version 2.18.0- https://www.powershellgallery.com/packages/Microsoft.Graph.Groups/2.18.0

Running this instead in my script, to force it to use the previous version 2.17.0, it works:

if (-not(Get-Module -ListAvailable -Name Microsoft.Graph.Groups)) { Install-Module -Name Microsoft.Graph.Groups -RequiredVersion '2.17.0' -Scope CurrentUser -AllowClobber -Force Import-Module -Name Microsoft.Graph.Groups }

SDK Version

2.18.0

Latest version known to work for scenario above?

2.17.0

Known Workarounds

Go back to the last known working version:

if (-not(Get-Module -ListAvailable -Name Microsoft.Graph.Groups)) { Install-Module -Name Microsoft.Graph.Groups -RequiredVersion '2.17.0' -Scope CurrentUser -AllowClobber -Force Import-Module -Name Microsoft.Graph.Groups }

Debug output

Click to expand log ```
</details>


### Configuration

Windows, x64

### Other information

.

marckean avatar Apr 25 '24 22:04 marckean

Hi @marckean thank you for reporting this issue. I successfully logged in after going through the reproduction steps. Kindly let me know which PowerShell version you are using. image

timayabi2020 avatar Apr 26 '24 05:04 timayabi2020

I am using version 2.17.0 now, whereas before using version 2.18.0 failed for me.

I am running:

if (-not(Get-Module -ListAvailable -Name Microsoft.Graph.Groups)) { Install-Module -Name Microsoft.Graph.Groups -Scope CurrentUser -AllowClobber -Force Import-Module -Name Microsoft.Graph.Groups }

Sign into the Microsoft Graph

$resource = "https://graph.microsoft.com"
$token = (Get-AzAccessToken -TenantId $tenantID -ResourceUrl $resource).Token

# Create a SecureString from the token
$SecureToken = ConvertTo-SecureString $token -AsPlainText -Force

# Use the SecureString token to connect
Connect-MgGraph -AccessToken $SecureToken

Note, as this doesn't specify a required version, it pulls the latest version (2.18.0). So adding this: -RequiredVersion '2.17.0' gets me past this error.

Also note, I am running this as an Azure Deployment Script resource which is executed using Bicep - for this, it spins up a container instance and runs the script.

marckean avatar Apr 26 '24 05:04 marckean

I'm experiencing same issue. Downgrading to v2.17 temporarily solves issue

KnudsenMorten avatar Apr 26 '24 12:04 KnudsenMorten

Same issue, downgrading to v2.17 is great workaround. My PS version info:

Name                           Value
----                           -----
PSVersion                      5.1.14393.6343
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.6343
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

dp-h avatar Apr 26 '24 16:04 dp-h

Could this be a PowerShell 5 problem? I have no issue connecting with a user provided access token and using the Groups module with PS 7.4.2 and SDK 2.18.

12Knocksinna avatar Apr 27 '24 23:04 12Knocksinna

@12Knocksinna I also have no issue connecting from PowerShell 5. image

timayabi2020 avatar Apr 29 '24 06:04 timayabi2020

I have the same issue.
My Azure automation accounts update their PowerShell Modules automatically in the early hours each Monday morning and therefore I received the new Microsoft.Graph versions this morning advertised on the PowerShell gallery 4 days ago. Since then two automation accounts' runbooks (that have worked since I moved to Microsoft.Graph In October 2023) have errored this morning with similar errors (see below). I use PowerShell Runtime version 5.1 and a User Managed Identity to authenticate - Cmdlets Get-MgGroup. Get-MgUser and Get-MgGroupMember have generated the following:

Error 1 Get-MgGroup : Method not found: 'Void Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[], Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'. At line:48 char:1 + $GroupID = Get-MgGroup -Filter "DisplayName eq 'everyone'" -Property ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-MgGroup_List], MissingMethodException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgGroup_List

Error 2 Get-MgUser : Method not found: 'Void Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[], Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'. At line:49 char:1 + $users = Get-MgUser -All + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-MgUser_List], MissingMethodException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_List

Error 3 Get-MgGroupMember : Cannot bind argument to parameter 'GroupId' because it is an empty string. At line:50 char:39 + $members = Get-MgGroupMember -GroupId $GroupID.Id -All + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-MgGroupMember], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Get-MgGroupMember

MainDBA avatar Apr 29 '24 07:04 MainDBA

As suggested by @marckean , @KnudsenMorten and @dp-h I have manually reverted all 3 modules from version 2.18.0 back down to version 2.17.0 in my Azure Automation Account and my runbooks complete OK without any errors/messages.

If it assists anyone else having this issue in Azure Automation, to revert back to an older stable version:

  • Download the relevant older version's *.nupg files from the PowerShell Gallery for the affected Microsoft.Graphs. packages.
  • Rename the file as a *.zip
  • Delete version 2.18.0 module from your Azure Automation account
  • Import the module in the portal using "+ Add A Module" > "Browse for file" > Locate your downloaded zip > "Import" Just be wary of dependencies - you may have to do this for all your Microsoft.Graph modules and import them in a particular order (in my case it Authentication, then Users and finally Groups worked without any dependency warnings)

MainDBA avatar Apr 29 '24 08:04 MainDBA

I noticed that two versions of Azure.Identity assembly are loaded in a PowerShell session but PowerShell 5 doesn't seem to handle the conflict well hence throwing the AzureIdentityAccessTokenProvider constructor error. Microsoft Graph PowerShell SDK uses the latest versions of Azure.Identity and Azure.Identity.Broker assemblies (1.11.0 and 1.1.0 respectively) while the Az.Accounts module still uses the old Azure.Identity assembly (1.10.3). I have seen a pull request in their GitHub repository to bump the Azure.Identity assembly up. The PR is yet to be merged.

So, if you are executing any scripts in a PowerShell 5 environment, please revert to 2.18.0 for now as suggested by @marckean, @KnudsenMorten, @dp-h and @MainDBA.

timayabi2020 avatar Apr 29 '24 15:04 timayabi2020

This seems to be the same type of issue as https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2148

PS C:\WINDOWS\system32> Import-Module Az.Accounts
PS C:\WINDOWS\system32> Import-Module Microsoft.Graph.Authentication
PS C:\WINDOWS\system32> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.19.0     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     2.18.0     Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, G...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...


PS C:\WINDOWS\system32> Get-MgApplication
Get-MgApplication : Method not found: 'Void
Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[],
Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'.
At line:1 char:1
+ Get-MgApplication
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-MgApplication_List], MissingMethodException
    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgApplication_List

PS C:\WINDOWS\system32> Get-MgOrganization
Get-MgOrganization : Method not found: 'Void
Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[],
Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'.
At line:1 char:1
+ Get-MgOrganization
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-MgOrganization_List], MissingMethodException
    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgOrganization_List

But when you flip the order of imports - things work

PS C:\WINDOWS\system32> Import-Module Microsoft.Graph.Authentication
PS C:\WINDOWS\system32> Import-Module Az.Accounts
PS C:\WINDOWS\system32> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.19.0     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     2.18.0     Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, G...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...


PS C:\WINDOWS\system32> Get-MgApplication
Get-MgApplication : Authentication needed. Please call Connect-MgGraph.
At line:1 char:1
+ Get-MgApplication
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-MgApplication_List], AuthenticationException
    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgApplication_List

peterboba avatar May 07 '24 11:05 peterboba

I noticed the Microsoft.Graph modules were updated to version 2.19.0 but this issue #2.18.0 was not included in the release notes - any updates on its progress please?

MainDBA avatar May 17 '24 11:05 MainDBA

@MainDBA from the linked fix Azure PowerShell, the Az 12.0 release should resolve this.

Ndiritu avatar May 17 '24 12:05 Ndiritu

I spotted Az 12.0.0 was made available earlier today (21/05) on the PowerShell Gallery so I ran my module update script and also moved my MS.Graph modules from [working] version 2.17.0 to 2.19.0 and my two affected automation accounts' runbooks have run OK, so, issue [for me] appears to be resolved. Thanks.

MainDBA avatar May 21 '24 11:05 MainDBA