Skip to content

Commit c39dcfb

Browse files
committed
Add docs for new .NET MethodInvocation tracing
Adds docs around the new .NET MethodInvocation tracing call introduced in PowerShell 7.6. This new tracing method allows you to see what method overload was invoked inside the tracing context.
1 parent 8ec07fe commit c39dcfb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

reference/7.6/Microsoft.PowerShell.Core/About/about_Methods.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,40 @@ specific overload of the **Bar** method.
257257
int: 1
258258
```
259259

260+
## Finding what overload was used
261+
262+
Since PowerShell 7.6, it is now possible to see what method overload was chosen
263+
by PowerShell. This is achieved through the new `MethodInvocation` tracing
264+
command.
265+
266+
This example shows how to use `Trace-Command` to display the overload chosen
267+
when calling the [String.Split method](/dotnet/api/system.string.split).
268+
269+
```powershell
270+
Trace-Command -PSHost -Name MethodInvocation -Expression {
271+
"a 1 b 1 c 1 d".Split(1)
272+
}
273+
274+
Trace-Command -PSHost -Name MethodInvocation -Expression {
275+
"a 1 b 1 c 1 d".Split("1")
276+
}
277+
```
278+
279+
```Output
280+
DEBUG: ... MethodInvocation Information: 0 : Invoking method: string[] Split(char separator, System.StringSplitOptions options = System.StringSplitOptions.None)
281+
282+
a 1 b 1 c 1 d
283+
284+
DEBUG: ... MethodInvocation Information: 0 : Invoking method: string[] Split(string separator, System.StringSplitOptions options = System.StringSplitOptions.None)
285+
a
286+
b
287+
c
288+
d
289+
```
290+
291+
In the first example the `1` was casted as a `[char]` and not a string causing
292+
the split output to split by `[char]1` and not the character `"1"`.
293+
260294
## Using .NET methods that take filesystem paths
261295

262296
PowerShell supports multiple runspaces per process. Each runspace has its own
@@ -275,3 +309,4 @@ method.
275309
- [about_Member-Access_Enumeration](about_Member-Access_Enumeration.md)
276310
- [about_Properties](about_Properties.md)
277311
- [Get-Member](xref:Microsoft.PowerShell.Utility.Get-Member)
312+
- [Trace-Command](xref:Microsoft.PowerShell.Utility.Trace-Command)

0 commit comments

Comments
 (0)