Closed jazzdelightsme closed 5 years ago
I debugged this with VS and I see a BOXED ReadOnlySpan<byte>
. Span<T>/ReadOnlySpan<T>
are special types that can't be boxed and must only live on the stack.
Note that the following command using the latest open source powershell, shows a better error message:
[System.MemoryExtensions]::AsSpan("Hello")
Cannot invoke the method "AsSpan" of the ByRef-like return type "System.ReadOnlySpan`1[System.Char]". ByRef-like types are not supported in PowerShell.
At line:1 char:1
+ [System.MemoryExtensions]::AsSpan("Hello")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : CannotCallMethodWithByRefLikeReturnType
Makes sense. Thanks @0xd4d !
Something is amiss with how PowerShell generates code to access a Span. (DbgShell currently uses Windows PowerShell 5.1 (latest Win10/.NET circa 1/1/2019).)
Repro steps:
Expected result: The last command should give you the first byte in the memory block.
Actual result:
When searching for more info about this sort of exception, I found reports that indicate it is the kind of thing that can happen when the C# compiler accidentally generates unverifiable IL. In this case, it's not the C# compiler, of course; it's the PowerShell script interpreter/compiler or maybe the Dynamic stuff it uses.
Expanded error info: