diff --git a/src/Microsoft.JSInterop/JSRuntimeBase.cs b/src/Microsoft.JSInterop/JSRuntimeBase.cs index db479652..09379396 100644 --- a/src/Microsoft.JSInterop/JSRuntimeBase.cs +++ b/src/Microsoft.JSInterop/JSRuntimeBase.cs @@ -100,10 +100,12 @@ namespace Microsoft.JSInterop if (succeeded) { var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs); - var resultValue = resultOrException is SimpleJson.JsonObject - ? ArgSerializerStrategy.DeserializeObject(resultOrException, resultType) - : resultOrException; - TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultValue); + if (resultOrException is SimpleJson.JsonObject || resultOrException is SimpleJson.JsonArray) + { + resultOrException = ArgSerializerStrategy.DeserializeObject(resultOrException, resultType); + } + + TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultOrException); } else { diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/InteropTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/InteropTest.cs index 2327cf5f..5553da71 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/InteropTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/InteropTest.cs @@ -59,6 +59,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests ["testDtoNonSerializedValueAsync"] = "99999", ["testDtoAsync"] = "Same", ["returnPrimitiveAsync"] = "123", + ["returnArrayAsync"] = "first,second", }; var expectedSyncValues = new Dictionary @@ -92,6 +93,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests ["testDtoNonSerializedValueSync"] = "99999", ["testDtoSync"] = "Same", ["returnPrimitive"] = "123", + ["returnArray"] = "first,second", }; // Include the sync assertions only when running under WebAssembly diff --git a/test/testapps/BasicTestApp/InteropComponent.cshtml b/test/testapps/BasicTestApp/InteropComponent.cshtml index 0579d911..41b7ad25 100644 --- a/test/testapps/BasicTestApp/InteropComponent.cshtml +++ b/test/testapps/BasicTestApp/InteropComponent.cshtml @@ -122,9 +122,11 @@ ReceiveDotNetObjectByRefAsyncResult["testDto"] = ReceiveDotNetObjectByRefAsyncResult["testDto"] == passDotNetObjectByRef ? "Same" : "Different"; ReturnValues["returnPrimitiveAsync"] = (await JSRuntime.Current.InvokeAsync("returnPrimitiveAsync")).ToString(); + ReturnValues["returnArrayAsync"] = string.Join(",", (await JSRuntime.Current.InvokeAsync("returnArrayAsync")).Select(x => x.Source).ToArray()); if (shouldSupportSyncInterop) { ReturnValues["returnPrimitive"] = ((IJSInProcessRuntime)JSRuntime.Current).Invoke("returnPrimitive").ToString(); + ReturnValues["returnArray"] = string.Join(",", ((IJSInProcessRuntime)JSRuntime.Current).Invoke("returnArray").Select(x => x.Source).ToArray()); } Invocations = invocations; diff --git a/test/testapps/BasicTestApp/wwwroot/js/jsinteroptests.js b/test/testapps/BasicTestApp/wwwroot/js/jsinteroptests.js index ef507150..10882d9e 100644 --- a/test/testapps/BasicTestApp/wwwroot/js/jsinteroptests.js +++ b/test/testapps/BasicTestApp/wwwroot/js/jsinteroptests.js @@ -186,6 +186,18 @@ function returnPrimitiveAsync() { }); } +function returnArray() { + return [{ source: 'first' }, { source: 'second' }]; +} + +function returnArrayAsync() { + return new Promise((resolve, reject) => { + setTimeout(function () { + resolve(returnArray()); + }, 100); + }); +} + function functionThrowsException() { throw new Error('Function threw an exception!'); }