Skip to content

'Method not found' exception when running Move-MgUserMessage #187

Closed

Description

@Windos

I've just updated to Microsoft.Graph 0.5.0 and tried using Move-MgUserMessage from Microsoft.Graph.Users.Actions.

When run, I get a Method not found exception calling out System.Net.Http.HttpClient Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(Microsoft.Graph.PowerShell.Authentication.IAuthContext)

I have observed this with both Windows PowerShell 5.1 and PowerShell 7.1 Preview 2

I had previously been running 0.2.1 of the Microsoft.Graph module suite and ran Update-Module Microsoft.Graph to update.

Full (redacted) code

$Cert = 'THUMBPRINT'
$AppId = 'GUID'
$TenantId = 'GUID'
$User = 'user@example.com'

$TestingFolder = 'FolderID'
$UnknownFolder = 'FolderID'

Connect-Graph -CertificateThumbprint $Cert -ClientId $AppId -TenantId $TenantId

$Messages = Get-MgUserMailFolderMessage -UserId $User -MailFolderId $TestingFolder
$Messages.Count

foreach ($Mail in $Messages) {
    Move-MgUserMessage -MessageId $Mail.Id -DestinationId $UnknownFolder
}

$Messages = Get-MgUserMailFolderMessage -UserId $User -MailFolderId $TestingFolder
$Messages.Count

Error

PS C:\Windows\System32> Get-Error

Exception             :
    Type       : System.MissingMethodException
    Message    : Method not found: 'System.Net.Http.HttpClient
Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(Microsoft.Graph.PowerShell.Authentication.IAuthContext)'.
    TargetSite :
        Name          : BeforeCreatePipeline
        DeclaringType : Microsoft.Graph.PowerShell.Module, Microsoft.Graph.Users.Actions.private, Version=0.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : Microsoft.Graph.Users.Actions.private.dll
    StackTrace :
   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.MoveMgUserMessage_MoveExpanded.ProcessRecordAsync()
    Source     : Microsoft.Graph.Users.Actions.private
    HResult    : -2146233069
CategoryInfo          : NotSpecified: (:) [Move-MgUserMessage_MoveExpanded], MissingMethodException
FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.MoveMgUserMessage_MoveExpanded
InvocationInfo        :
    MyCommand        : Move-MgUserMessage_MoveExpanded
    ScriptLineNumber : 2
    OffsetInLine     : 5
    HistoryId        : 10
    Line             :     Move-MgUserMessage -MessageId $Mail.Id -UserId $User -DestinationId $UnknownFolder

    PositionMessage  : At line:2 char:5
                       +     Move-MgUserMessage -MessageId $Mail.Id -UserId $User -Destination …
                       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Move-MgUserMessage
    CommandOrigin    : Internal
ScriptStackTrace      : at Move-MgUserMessage<Process>, C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Users.Actions\0.5.0\exports\ProxyCmdletDefinitions.ps1: line 26239                               at <ScriptBlock>, <No file>: line 2
PipelineIterationInfo :

Environment

Windows PowerShell 5.1

PS C:\Users\Windos> $PSVersionTable

Name                           Value                                                                                                                                                            
----                           -----                                                                                                                                                            
PSVersion                      5.1.18362.752                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                          
BuildVersion                   10.0.18362.752                                                                                                                                                   
CLRVersion                     4.0.30319.42000                                                                                                                                                  
WSManStackVersion              3.0                                                                                                                                                              
PSRemotingProtocolVersion      2.3                                                                                                                                                              
SerializationVersion           1.1.0.1  
ModuleType Version    Name                                ExportedCommands                                                                                                                      
---------- -------    ----                                ----------------                                                                                                                      
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                                                                   
Script     0.2.0      Microsoft.Graph.Authentication      {Connect-Graph, Disconnect-Graph, Get-MgContext}                                                                                      
Script     0.5.0      Microsoft.Graph.Users.Actions       {Clear-MgUserAndBlockManagedApp, Clear-MgUserManagedAppRegistration, Clear-MgUserManagedDevice, Clear-MgUserWindowInformationProtec...
Script     0.2.1      Microsoft.Graph.Users.Mail          {Get-MgUserInferenceClassification, Get-MgUserInferenceClassificationOverride, Get-MgUserMailFolder, Get-MgUserMailFolderChildFolde...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                                                                    
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}                                             
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, Enable-WSManCredSSP...}        

PowerShell 7.1

PS C:\Windows\System32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.2
PSEdition                      Core
GitCommitId                    7.1.0-preview.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS C:\Windows\System32> Get-Module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.2.0                 Microsoft.Graph.Authentication      {Connect-Graph, Disconnect-Graph, Get-MgContext}
Script     0.5.0                 Microsoft.Graph.Users.Actions       {Clear-MgUserAndBlockManagedApp, Clear-MgUserManagedAppRegistration, Clear-MgUserManagedDevice, Clear-MgUserWindowInf… 
Script     0.2.1                 Microsoft.Graph.Users.Mail          {Get-MgUserInferenceClassification, Get-MgUserInferenceClassificationOverride, Get-MgUserMailFolder, Get-MgUserMailFo… Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     2.0.1                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

Activity

  1. Windos commented on May 2, 2020

    @Windos
    Author

    I believe this will be related to #165

    When running Update-Module Microsoft.Graph the only thing being updated is the wrapper module and in addition any new modules are being installed (hence I got the Users.Actions one I was looking for). But because a minimum version isn't being specified, existing modules like Authentication and Users.Mail were left at whatever they were installed at (in the case of Authentication I'm still lagging back at 0.2.0!)

    In order to actually update all of the components, I'm having to now run Update-Module Microsoft.Graph* but this means I need to consent to every single update... and there's a lot of them (it's already a slow install, this marks it really bad)

    image

  2. Windos commented on May 2, 2020

    @Windos
    Author

    I know this is turning into a branching comedy of issues, but it's the path I'm taking trying to troubleshoot both for others having the same issues and hopefully it being better for others in the future.

    I gave up on consenting to updating every individual package and deleted the currently installed version(s) of the module and install fresh.

    It now gives me an error when running Get-MgUserMailFolderMessage:

    Get-MgUserMailFolderMessage : Could not load file or assembly 'Microsoft.Graph.Authentication, Version=0.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 
    The system cannot find the file specified.
    

    I manually install that specific version of Microsoft.Graph.Authentication:

    Install-Module Microsoft.Graph.Authentication -RequiredVersion 0.2.0

    AND then manually import it:

    Import-Module Microsoft.Graph.Authentication -RequiredVersion 0.2.0

    .... 🤦‍♂️ same error as what I started with, just on a different cmdlet.

    image


    I guess this issue can be summed up with:

    • There's a confusing weave of module/dll versions here.
    • Updates don't work currently, as existing child modules don't get updated.
    • New installs don't work because some modules are being tied to older dlls/assemblies.
  3. peombwa commented on May 4, 2020

    @peombwa
    Member

    Hi Josh King (@Windos), thanks for the detailed repro steps.
    The error you seeing is due to change that we made on how we store the access token in a users session. You need to update all modules to 0.5.0. Run Update-Module Microsoft.Graph -Force to update all modules plus their dependencies to 0.5.0.

  4. Windos commented on May 7, 2020

    @Windos
    Author

    Can confirm this issue is fixed with 0.5.1 (#206) - thanks teams (and Peter Ombwa (@peombwa))

  5. ghost removed on May 7, 2020
  6. JustinGrote commented on Jul 8, 2021

    @JustinGrote

    Peter Ombwa (@peombwa) I got this error with Get-MgDirectorySetting, is it related or should I file a new issue?

    Exception             : 
        Type       : System.MissingMethodException
        Message    : Method not found: 'System.Net.Http.HttpClient
    Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(Microsoft.Graph.PowerShell.Authentication.IAuthContext)'.
        TargetSite : 
            Name          : BeforeCreatePipeline
            DeclaringType : Microsoft.Graph.PowerShell.Module
            MemberType    : Method
            Module        : Microsoft.Graph.Identity.DirectorySettings.private.dll
        StackTrace : 
       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.GetMgDirectorySetting_List.ProcessRecordAsync()
        Source     : Microsoft.Graph.Identity.DirectorySettings.private
        HResult    : -2146233069
    CategoryInfo          : NotSpecified: (:) [Get-MgDirectorySetting_List], MissingMethodException
    FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgDirectorySetting_List
    InvocationInfo        : 
        MyCommand        : Get-MgDirectorySetting_List
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 9
        Line             : Get-MgDirectorySetting
        PositionMessage  : At line:1 char:1
                           + Get-MgDirectorySetting
                           + ~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Get-MgDirectorySetting
        CommandOrigin    : Internal
    ScriptStackTrace      : at Get-MgDirectorySetting<Process>, C:\Users\JGrote\OneDrive - Allied Digital Services
    LLC\Documents\PowerShell\Modules\Microsoft.Graph.Identity.DirectorySettings\0.9.1\exports\v1.0-beta\ProxyCmdletDefinitions.ps1: line 190
                            at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo : 
    
     gmo Microsoft.graph* -ListAvailable
    
        Directory: C:\Users\JGrote\OneDrive - Allied Digital Services LLC\Documents\PowerShell\Modules
    
    ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
    ---------- -------    ---------- ----                                --------- ----------------
    Script     1.6.0                 Microsoft.Graph.Authentication      Core,Desk {Connect-MgGraph, Disconnect-MgGraph, G…
    Script     0.9.1                 Microsoft.Graph.Identity.Directory… Core,Desk {Get-MgDirectorySetting, Get-MgGroupSet…
    

    Looks like the method signature is there to me...

    [Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers]::GetGraphHttpClient
    
    OverloadDefinitions
    -------------------
    static System.Net.Http.HttpClient GetGraphHttpClient(Microsoft.Graph.PowerShell.Authentication.IAuthContext
    authContext)
    static System.Net.Http.HttpClient GetGraphHttpClient(Microsoft.Graph.IAuthenticationProvider authProvider)
    
  7. peombwa commented on Jul 8, 2021

    @peombwa
    Member

    Justin Grote (@JustinGrote) This is because you are using a deprecated module - Microsoft.Graph,Identity.DirectorySettings 0.9.1. Use Microsoft.Graph.Identity.DirectoryManagement v1.6.0 instead.

    As noted here #744, I'll update all 0.9.1 to warn customers that they are using a deprecated module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions