Error: Microsoft.JSInterop.JSException: Converting circular structure to JSON in .NET7
Asked Answered
T

1

17

I have created a Blazor Server application in .NET6.but recently I've upgraded it to.NET7.since this time,i am getting above issue .

Error: Microsoft.JSInterop.JSException: Converting circular structure to JSON --> starting at object with constructor 'Window' --- property 'window' closes the circle TypeError: Converting circular structure to JSON --> starting at object with constructor 'Window' --- property 'window' closes the circle at JSON.stringify ()

this issue is occurring from this line

await _jsRuntime.InvokeAsync<object>("open", url, "_blank");

this line is responsible for opening a URL in a new tab on the browser. once I click on a navigation bar link, the above line is called and occurred this issue.is there anybody who knows an answer to this issue? please help me, appreciate all your answers.

Theodor answered 15/8, 2022 at 9:14 Comment(0)
T
38

I changed this line

await _jsRuntime.InvokeAsync<object>("open", url, "_blank");

as this

await _jsRuntime.InvokeVoidAsync("open", url, "_blank");

after that, I didn't get that issue.

Theodor answered 18/8, 2022 at 6:6 Comment(3)
Good catch. I've also ran into the same problem and this fix worked like a charm. Thank you!Countrywide
Can somebody explain why this is the case?Gittens
More details about why this is happening can be found here: github.com/dotnet/aspnetcore/issues/16632Restaurateur

© 2022 - 2024 — McMap. All rights reserved.