Skip to content

Commit de51bc1

Browse files
author
Max Pixel
committed
fix(sdk/dotnet): properly stringify KeyValuePair in exception logging
1 parent 28b2716 commit de51bc1

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

sdk/dotnet/Thunk/Invocation.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,20 @@ private static void PrintPropertyValue(string propertyName, object? value, int d
185185
return;
186186
}
187187

188-
// If the value can be printed directly, do so now
188+
// Handle KeyValuePair specifically
189+
Type valueType = value.GetType();
190+
if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
191+
{
192+
var keyProperty = valueType.GetProperty("Key")!;
193+
var valueProperty = valueType.GetProperty("Value")!;
194+
var key = keyProperty.GetValue(value)?.ToString() ?? "null";
195+
var pairValue = valueProperty.GetValue(value);
196+
197+
Console.Error.WriteLine($"{indent}{propertyName}:");
198+
PrintPropertyValue(key, pairValue, depth + 1, visited);
199+
return;
200+
}
201+
189202
if (ShouldPrintDirectly(value))
190203
{
191204
Console.Error.WriteLine($"{indent}{propertyName}: {value}");

0 commit comments

Comments
 (0)