Repository navigation
Labels
Description
Steps to reproduce
New-MgTeamMember -TeamId $teamId -AdditionalProperties @{"@odata.type" = "microsoft.graph.aadUserConversationMember"; "user@odata.bind" = "https://graph.microsoft.com/beta/users/"+$user.Id} -Roles "owner" -DebugExpected behavior
New-MgTeamMember should succeed without throwing an exception in PowerShell 5.1.
Actual behavior
New-MgTeamMember throws ObjectDuObjectDisposedException despite the cmdlet succeeding in PowerShell 5.1.
DEBUG: CmdletException: ObjectDisposedException - Cannot access a disposed object.
Object name: 'System.Net.Http.StringContent'. : at System.Net.Http.HttpContent.CheckDisposed()
at System.Net.Http.HttpContent.ReadAsStreamAsync()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Microsoft.Graph.PowerShell.HttpMessageFormatter.TryComputeLength(Int64& length)
at System.Net.Http.HttpContent.GetComputedOrBufferLength()
at System.Net.Http.Headers.HttpContentHeaders.get_ContentLength()
at System.Net.Http.HttpContent.CreateMemoryStream(Int64 maxBufferSize, Exception& error)
at System.Net.Http.HttpContent.LoadIntoBufferAsync(Int64 maxBufferSize)
at System.Net.Http.HttpContent.ReadAsStringAsync()
at Microsoft.Graph.PowerShell.Module.<Finally>d__5.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__4.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__30.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.NewMgTeamMember_CreateExpanded1.<Microsoft-Graph-PowerShell-Runtime-IEventListener-Signal>d__64.MoveNext()Environment data
PS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\WINDOWS\system32> Get-InstalledModule Microsoft.Graph
Version Name Repository Description
------- ---- ---------- -----------
0.9.1 Microsoft.Graph PSGallery Microsoft Graph PowerShell module
Workaround
Use PowerShell 7+ to run the cmdlet. This can be installed from https://github.com/PowerShell/PowerShell/releases.
Activity
peombwa commentedon Aug 14, 2020
This can be fixed by reading the request content in "BeforeCall" event and not "Finally" event (request content has already been disposed at this event). This should look like this:
georgend commentedon Sep 2, 2020
Related to #354