Skip to content

Commit 8ccaf89

Browse files
committed
JSInterop: Enable returning null for a nullable value type
When a result value is null, and the return type is a nullable value type, Convert.ChangeType throws instead of returning the null value. dotnet#30366
1 parent d81725e commit 8ccaf89

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/JSInterop/Microsoft.JSInterop/src/Infrastructure/TaskGenericsUtil.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public void SetResult(object tcs, object? result)
8989
// If necessary, attempt a cast
9090
var typedResult = result is T resultT
9191
? resultT
92-
: (T)Convert.ChangeType(result, typeof(T), CultureInfo.InvariantCulture)!;
92+
: result == null && default(T) == null
93+
? default(T)
94+
: (T)Convert.ChangeType(result, typeof(T), CultureInfo.InvariantCulture)!;
9395

9496
typedTcs.SetResult(typedResult!);
9597
}

0 commit comments

Comments
 (0)