Registry Mirror
Skip to content

Update-MgUser - Cannot access a disposed object System.Net.Http.StringContent #2191

Closed

Description

@0x0309

When I run Update-MgUser -Id "id-of-user" -DisplayName "the name" I get the following error:
Update-MgUser : One or more errors occurred

Interestingly, the name change is applied, the error is while reading the response.
Get-MgUser works as expected.

$error[0].Exception.ToString() shows

System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.StringContent'.
   at System.Net.Http.HttpContent.CheckDisposed()
   at System.Net.Http.HttpContent.CopyToAsync(Stream stream, TransportContext context)
   at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<CloneAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<GetHttpRequestLogAsync>d__1.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Microsoft.Graph.PowerShell.EventFactory.CreateLogEvent(Task`1 message)
   at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<>c__DisplayClass424_0.<Microsoft.Graph.PowerShell.Runtime.IEventListener.Signal>b__1()
   at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<Microsoft-Graph-PowerShell-Runtime-IEventListener-Signal>d__424.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Module.<OnResponseCreated>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Module.<EventHandler>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Module.<Signal>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<Microsoft-Graph-PowerShell-Runtime-IEventListener-Signal>d__424.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Users.<UserUpdateUser_Call>d__697.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Graph.PowerShell.Users.<UserUpdateUser_Call>d__697.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Users.<UserUpdateUser>d__695.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<ProcessRecordAsync>d__426.MoveNext()
---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.StringContent'.
   at System.Net.Http.HttpContent.CheckDisposed()
   at System.Net.Http.HttpContent.CopyToAsync(Stream stream, TransportContext context)
   at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<CloneAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<GetHttpRequestLogAsync>d__1.MoveNext()<---

This was working a few weeks ago, not sure why this is occurring now.

Powershell v5.1.22621.1778
Tested in pwsh and the error does not occur.

Microsoft.Graph v2.1.0

Activity

  1. timayabi2020 commented on Jul 27, 2023

    @timayabi2020
    Contributor

    Hi 0x0309, thank you for bringing up this issue. We have realized that such an issue is common with PowerShell 5.1, as a work around try using PowerShell 7. Also please let us know if it's an intermittent or a constant issue. An almost similar issue was also logged here.
    Meanwhile we will investigate further and hopefully provide a permanent fix.

  2. GraphiteCA commented on Aug 1, 2023

    @GraphiteCA

    I encountered a similar issue with #2203 , the issue was constant.
    Upgrading to PowerShelll 7 isn't a super viable workaround in my environment (at the moment), I eagerly await resolution. :)

  3. bunderwood commented on Aug 2, 2023

    @bunderwood

    I am having the same issue. It only occurs in VS Code with the PowerShell extension. I have spent several days now trying to work out the precise issue and workarounds. Using PS v7 in VS Code works for MS Graph, but there are other major changes and deprecations between v5 and v7 that make changing versions for all of our dev machines, servers, and scheduled tasks is complete infeasible for us.

    This issue does not exist within a pure PS 5 terminal or PS ISE (which I cannot stand).

    Thank you both -- and Peter Ombwa (@peombwa) for the PR. I hope this gets resolved soon. We are unable to develop in VS Code as we used to now that we are (also, BTW) forced to used MS Graph due to the throttling and deprecation of the MSOnline cmdlets as of last week.

  4. bunderwood commented on Aug 2, 2023

    @bunderwood

    Trying to Update-MGUser

    In PowerShell 5.1 in VS Code, fails here:
    image

    System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'System.Net.Http.StringContent'.
       at System.Net.Http.HttpContent.CheckDisposed()
       at System.Net.Http.HttpContent.CopyToAsync(Stream stream, TransportContext context)
       at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<CloneAsync>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<GetHttpRequestLogAsync>d__1.MoveNext()
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at Microsoft.Graph.PowerShell.EventFactory.CreateLogEvent(Task`1 message)
       at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<>c__DisplayClass424_0.<Microsoft.Graph.PowerShell.Runtime.IEventListener.Signal>b__1()
       at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<Microsoft-Graph-PowerShell-Runtime-IEventListener-Signal>d__424.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Module.<OnResponseCreated>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Module.<EventHandler>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Module.<Signal>d__32.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<Microsoft-Graph-PowerShell-Runtime-IEventListener-Signal>d__424.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Users.<UserUpdateUser_Call>d__697.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.Graph.PowerShell.Users.<UserUpdateUser_Call>d__697.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Users.<UserUpdateUser>d__695.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded.<ProcessRecordAsync>d__426.MoveNext()
    ---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'System.Net.Http.StringContent'.
       at System.Net.Http.HttpContent.CheckDisposed()
       at System.Net.Http.HttpContent.CopyToAsync(Stream stream, TransportContext context)
       at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<CloneAsync>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Graph.PowerShell.HttpMessageLogFormatter.<GetHttpRequestLogAsync>d__1.MoveNext()<---
    
  5. peombwa commented on Aug 2, 2023

    @peombwa
    Member

    Thanks for repro steps and logs!

    A fix for the issue will be provided by #2209, which is scheduled to go out as part of next week's refresh. The underlaying .NET runtime (4.x) that's used by the VS Code with the PowerShell extension has a bug that disposes the HttpContent before our log formatter can access it; hence, the error.

    As a workaround, please use the standalone PowerShell 5.1 (not VS Code extension) or PowerShell 7 to run the command.

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions