question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular references are not supported, take two

See original GitHub issue

As correctly mentioned in #18628, blazor currently doesn’t support circular references to be serialized. But I’m very confused as to what happened to that issue. It’s clear from the sources that the current implementation uses JSON.stringify before actually invoking the C# code and that function throws a TypeError: cyclic object value when you pass it an object that contains circular references.

#18628 was closed because this is covered in an external issue (https://github.com/dotnet/runtime/issues/30820) but I don’t understand how that’s the case. It’s true that the serializer can’t handle circular references yet but once that issue is fixed and the serializer does have support for that, the error in blazor will persist. That’s because the error already happens at JSON.stringify which isn’t affected by blazor.

I debugged it manually by building and including the source from Microsoft.JSInterop.JS. When you step through the code you can see that the error happens at JSON.stringify (in my case at Line 61 / invokePossibleInstanceMethod). This is the case when synchronously invoking C# code from JavaScript with an argument that contains circular references. The error that happens is as follows (in Firefox):

TypeError: cyclic object value

When you do it the other way around (invoke JavaScript from C# with a return value that contains circular references), the error will be rethrown in C# and the error changes to the following. When you debug it you can observe that it’s also thrown at a JSON.stringify call.

WASM: Microsoft.JSInterop.JSException: cyclic object value

From my understanding, the error would be exactly the same if the serializer was able to handle circular references because the exception is thrown in JavaScript at JSON.stringify and doesn’t ever reach the .NET serializer.

Am I completely missing the point here or are my assumptions correct? I would’ve commented on the other issue but it’s locked.
If I’m correct, will this be supported once https://github.com/dotnet/runtime/issues/30820 is implemented? I’m in need of a solution right now so I’ll have to take a look at flatted or something similar in the meantime.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
user72356commented, Sep 24, 2020

I have the exact same problem as @Joelius, with the same use case of trying to wrap a JS library in Blazor Webassembly. I need to return complex JS objects to .Net, that include references, some of them circular. I would like the ability to: 1. Detect and ignore the circular references; 2. Set a maximum depth of serialization.

0reactions
Joelius300commented, Sep 24, 2020

@gb1337 The depth of serialization issue might get fixed with #12685. Make sure to explain your use-case there, it’ll increase the chances of it being implemented soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove or allow a circular reference
Press Ctrl+X to cut the formula, select another cell, and press Ctrl+V to paste it. Tips: At times, you may want to use...
Read more >
Circular reference ASPNET
I just want to say that I'm not that familiar with aspnet first. I have been given this 6 yo application that Im...
Read more >
Circular reference in Excel: how to find, enable, use, or ...
Learn the basics of Excel circular reference - how to check workbooks for circular formulas, and how to enable, find and remove circular ......
Read more >
How to Find Circular References in Excel
To find circular references in Excel, use the “Error Checking” tool under the “Formulas” tab to identify cells with a circular dependency.
Read more >
How To Find Circular References In Excel (And Fix Them)
To find a circular reference is easier than you think. You simply need to use the “Circular References” feature under the Formulas tab....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found