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.

Class with property interface of List

See original GitHub issue

If you have class:

class ClassWithPropertyInterfaceOfList
        {
            public IList<string> List { get; set; }
            public IDictionary<string, string> Dictionary { get; set; }

            public ISet<string> Set { get; set; }
        }

and create object:

            var expected = new ClassWithPropertyInterfaceOfList
            {
                List = new List<string> { "Item1" },
                Set = new HashSet<string> { "Item1" },
                Dictionary = new Dictionary<string, string> { { "Key", "Value" } }
            };

I’ve got exception:

ExtendedXmlSerializer.ExtensionModel.References.CircularReferencesDetectedException was unhandled by user code HResult=-2146233088 Message=The provided instance of type ‘ExtendedXmlSerializer.Tests.ExtensionModel.Xml.ExtendedXmlSerializerTests+ClassWithPropertyInterfaceOfList’ contains circular references within its graph. Serializing this instance would result in a recursive, endless loop. To properly serialize this instance, please create a serializer that has referential support enabled by extending it with the ReferencesExtension. Source=ExtendedXmlSerializer StackTrace: at ExtendedXmlSerializer.ExtensionModel.References.ReferenceAwareSerializers.Serializer.Write(IFormatWriter writer, Object instance) in C:\Work\ExtendedXmlSerializer\src\ExtendedXmlSerializer\ExtensionModel\References\ReferenceAwareSerializers.cs:line 77 at ExtendedXmlSerializer.ExtensionModel.Xml.ExtendedXmlSerializer.Serialize(XmlWriter writer, Object instance) in C:\Work\ExtendedXmlSerializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\ExtendedXmlSerializer.cs:line 55 at ExtendedXmlSerializer.ExtensionModel.Xml.InstanceFormatter.Get(Object parameter) in C:\Work\ExtendedXmlSerializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\InstanceFormatter.cs:line 50 at ExtendedXmlSerializer.ExtensionModel.Xml.Extensions.Serialize(IExtendedXmlSerializer this, IXmlWriterFactory factory, Func`1 stream, Object instance) in C:\Work\ExtendedXmlSerializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\Extensions.cs:line 132 at ExtendedXmlSerializer.ExtensionModel.Xml.Extensions.Serialize(IExtendedXmlSerializer this, Object instance) in C:\Work\ExtendedXmlSerializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\Extensions.cs:line 118 at ExtendedXmlSerializer.Tests.Support.SerializationSupport.Assert[T](T instance, String expected) in C:\Work\ExtendedXmlSerializer\test\ExtendedXmlSerializer.Tests\Support\SerializationSupport.cs:line 46 at ExtendedXmlSerializer.Tests.ExtensionModel.Xml.ExtendedXmlSerializerTests.PropertyInterfaceOfList() in C:\Work\ExtendedXmlSerializer\test\ExtendedXmlSerializer.Tests\ExtensionModel\Xml\ExtendedXmlSerializerTests.cs:line 205 InnerException:

I’ll add test to repo.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:39 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
Mike-E-angelocommented, Jul 22, 2019

v3 it’s an unofficial project at the moment, and I probably shouldn’t have mentioned it. Trying to pump myself into it. 😆

For some context, the plan is to create a new serializer as a separate project that supports numerous formats and then have ExtendedXmlSerializer be the XML version (along with classical support).

I emphasize plan as every developer has a plan until their code punches them in their face. 🤣 That’s how it is for me, anyway.

In any case, I have captured our discussion here: https://github.com/SuperDotNet/Super.NET/issues/27

1reaction
MagicAndre1981commented, Jul 17, 2019

ok, the code stops because I configured VS to stop at this exception. I see the code works and generates XML and deserialized objects include the references again.

I see you catch the exception and ignore it by still writing the content in ReferenceAwareSerializers.cs

catch (CircularReferencesDetectedException e)
{
     e.Writer.Write(writer, instance);
}

I configured VS to stop because I saw this CircularReferencesDetectedException before app closes and debugging stops 🤔 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - List<T> as a property on an interface
If you are using .NET 4.0 or newer you can use the built in MemoryCache class and don't need to rely on any...
Read more >
Interface Properties - C# Programming Guide
The accessors indicate whether the property is read-write, read-only, or write-only. Unlike in classes and structs, declaring the accessors ...
Read more >
List Interface in Java with Examples
The implementation classes of the List interface are ArrayList, LinkedList, Stack, and Vector. ArrayList and LinkedList are widely used in ...
Read more >
Interfaces - TypeScript: Handbook
Not all properties of an interface may be required. Some exist under certain conditions or may not be there at all. These optional...
Read more >
c# - Interface properties implementation
A good class exposes functionality and hides state. When a property is exposed rather than a functional method using that state then take...
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