-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
I have discovered a situation when attempting to build and use a portable PDB file which is causing a performance degredation in my application by emitting unneccessary exceptions when collecting stack traces (for exceptions).
runtime/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.cs
Line 66 in bd5f6eb
| if (handle.Kind == HandleKind.MethodDefinition) |
There is at least one situation where this code can be entered into with a handle of value 0x06000000. That is, technically, a nil token, but with an invalid row ID. In the case I have observed it is because a dynamic method is on the stack and that dynamic method is attached to an existing type from an assembly with an associated portable PDB.
Thus the check in StackTraceSymbols which checks if it's Kind == MethodDef succeeds. The code continues, converts it to a MethodDebugInformation token, and then attempts to look it up from the MetadataReader, which then calls Throw.OutOfBounds. Which causes another exception.
The problem seems to appear all the way back to .NET 6.