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.

EnableImplicitTypingFromAll breaks EnableReferences

See original GitHub issue

I’m new to this library so still playing around with how ConfigurationContainer works. Apologies if this is the intended behavior.

Here’s a simplified version of my data structures:

public class MainDTO
{          
    public SubDTO Sub1 { get; set; } = new SubDTO();
    public SubDTO Sub2 { get; set; } = new SubDTO();
    public SubDTO Sub3 { get; set; } = new SubDTO();
            
}

public class SubDTO
{
    public SubSubDTO SubSub1 { get; set; } = SubSubDTO.NullObject;

}

public class SubSubDTO
{
    public static SubSubDTO NullObject { get; } = new SubSubDTO();

    public string Id { get; set; } = Guid.NewGuid().ToString();
}

And here is my container

var serializer = new ConfigurationContainer()
                .UseAutoFormatting()
                .UseOptimizedNamespaces()
                .EnableImplicitTyping(new[] {
                    typeof(MainDTO), // <-- this causes assertion error
                    typeof(SubDTO),
                    typeof(SubSubDTO)
                })
                .Type<SubSubDTO>()
                    .EnableReferences(definition => definition.Id)                
                .Create();

I would expect all SubDTO objects in MainDTO to be different objects that hold a reference to the same SubSubDTO object.

Here is the output

<?xml version="1.0" encoding="utf-8"?>
<SerializerPlayground-MainDTO xmlns="clr-namespace:UnitTests.RecipeTests;assembly=UnitTests">
  <Sub1>
    <SubSub1 Id="78238952-0d09-48dd-8725-4a7326fa897b" />
  </Sub1>
  <Sub2>
    <SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
  </Sub2>
  <Sub3>
    <SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
  </Sub3>
</SerializerPlayground-MainDTO>

This looks right, at least they reference the correct ids. But when I deserialize it, Sub1 is correct but the other two have new Guids.

I tracked down the culprit to this line:

.EnableImplicitTyping(typeof(MainDTO))

If I take this out, all works as expected.

Another strange thing, if MainDTO references SubSubDTO directly (instead of the middle object) it works fine, even when enabling implicit typing for all types.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
gmkadocommented, Jul 6, 2020

Hey @Mike-E-wins I’m doing my own reference resolving after deserialization, so I likely won’t come back to this. Just FYI in case you want to close the issue.

1reaction
gmkadocommented, Jun 10, 2020

Hi @Mike-E-wins , works on my end. Thanks for updating the documentation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable implicit type conversion from non-const ...
That is, I have a non-const pointer that I'd like to pass into a function that accept a const pointer by reference. All...
Read more >
Allow chained member references in implicit ...
When the type of an expression is implied by the context, Swift allows developers to use what is formally referred to as an...
Read more >
Code Syntax Style: Implicit/Explicit Typing ('var' Keyword)
Configure preferences of using 'var' keyword in the Options dialog · Go to the Code Editing | C# | Syntax Style page of...
Read more >
Implicit Using Statements In .NET 6 - NET Core Tutorials
When enabled, implicit usings are actually a hidden auto generated file, inside your obj folder, that declares global using statements behind the scenes....
Read more >
Implicit none and carry on. Fortran ...
Fortran has an interesting historic feature called implicit typing: Undeclared variables whose name begins with letters i, j, k, l, m, ...
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