You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$Context.CurrentFile.GetText not compatible with $Context.SelectedRange #1496
I would expect the $Context.SelectedRange to work directly with the GetText method which take a FileRange as argument.
That does not end there.
When working with Powershell 7.2, the Microsoft.PowerShell.EditorServices.Extensions.FileRange type does not exist so not only the way you'd expect it to work does not work but also the workaround of creating a new object of the aforementionned type manually and pasting value from the context range do not work either.
The error in a PS 7,2 VSCode session with GetText and $Context.SelectedRange
MethodException: Cannot find an overload for "GetText" and the argument count: "1".
The error in a PS 7.2 VSCode session when trying to create a filerange object manually
InvalidOperation: Unable to find type [Microsoft.PowerShell.EditorServices.Extensions.FileRange].
The workaround as written above doesn't work for me. I get "InvalidOperation: Unable to find type [Microsoft.PowerShell.EditorServices.Extensions.FileRange]."
I can use Add-Type to recognize the type, but this also feels fragile, and there is still a problem:
Activity
andyleejordan commentedon Jun 14, 2021
This is interesting but a bit obscure to get fixed for the time being. I've marked it as up-for-grabs in case someone else wants to take a look.
BrianL-STCU commentedon Mar 19, 2026
Just noticed this problem in PowerShell 7.6. This is kind of a kludgy workaround, it would be nice to fix.
BrianL-STCU commentedon Mar 19, 2026
The workaround as written above doesn't work for me. I get "InvalidOperation: Unable to find type [Microsoft.PowerShell.EditorServices.Extensions.FileRange]."
I can use
Add-Typeto recognize the type, but this also feels fragile, and there is still a problem:Accept `IFileRange` in `FileContext.GetText` overloads (#2306)