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.

Discussion Around Parameterized Content

See original GitHub issue

Given the class…

public class Person
{
    private IList<Person> _friends = new List<Person>();

    public Person(string name)
    {
        Name = name;
    }

    public Person()
    {
    }

    public string Name { get; set; }

    public IList<Person> Friends
    {
        get => _friends;
        set => _friends = value ?? throw new ArgumentNullException();
    }
}

And invoking it as such:

       var snoopy = new Person("Snoopy");
        var charlieBrown = new Person("Charles \"Charlie\" Brown");
        var sallyBrown = new Person("Sally Brown");
        var marcie = new Person("Marcie");

        snoopy.Friends.Add(charlieBrown);
        snoopy.Friends.Add(sallyBrown);
        snoopy.Friends.Add(marcie);
        snoopy.Friends.Add(charlieBrown); // added twice -- intentional

       var serializer = new ConfigurationContainer().EnableParameterizedContent().EnableReferences().Create();
        
        var serializedPerson = serializer.Serialize(snoopy);
        snoopy = serializer.Deserialize<Person>(serializedPerson);

The serialization will all work as expected, but an exception will be thrown on deserialization:

The value "ExtendedXmlSerializer.ExtensionModel.Types.ActivationContext" is not of type "ExsTests.Person" and cannot be used in this generic collection. Parameter name: value

If you comment out the last Friends.Add then the object will be properly deserialized but snoopy will be an empty object - no Friends, no Name. Please fix poor ol’ Snoopy!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
FaustoNascimentocommented, Sep 19, 2018

This issue is resolved and can be closed, yes. Although could you explain exactly what the extension WritableParameterizedContentExtension (as per #196) does?

It seems to me like it just allows public setters on properties set by the ctor, but not sure if that’s the case?

1reaction
FaustoNascimentocommented, Sep 19, 2018

You have to keep in mind that we have basically shelved this version as we work towards v3.

Apologies, wasn’t aware of this, thought that while you were working towards v3, that v2 was still being actively maintained and improved (rather than just bug fixing).

I agree it’s not ideal but it seems that you are under the impression that it is the project that is blocking you here.

Well, not quite. Redesigning my classes is not really an option (having an empty private ctor is an option but it feels like dodging the problem rather than fixing it). But I don’t see it as this project blocking me. I’ve always had alternatives but I thought that v2 was still being actively worked on and that as such I was contributing to this project by highlighting things that are important for developers like myself.

I don’t mind creating my own extensions and submitting a PR when they’re done - I’d actually prefer it since I’d end up with the knowledge about how to create my own extensions. But right now I don’t feel like I know enough about all of the different classes involved to create my own.

So long as you’re happy to potentially devoting more time to teaching me what each class does than what it would take you to implement it I have no problems with creating an extension and submitting a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

php - What is parameterized query?
A parameterized query is a query in which placeholders are used for parameters and the parameter values are supplied at execution time. Why...
Read more >
Performance Implications of Parameterized Queries
The Simple Parameterization Feature​​ In cases in which values are specified explicitly, as in Listings 1 and 2, SQL Server invokes a feature ......
Read more >
Solved Q1 Discuss the different ways we used parameterized
Question: Q1 Discuss the different ways we used parameterized SQL statements. Higher grades given for more detailed, specific and accurate responses, that use ......
Read more >
Give me parameterized SQL, or give me death
Non-parameterized SQL is the GoTo statement of database programming. ... passing the field data content as a string into a larger string, ...
Read more >
How and Why to Use Parameterized Queries
A parameterized query is a query in which placeholders are used for parameters and the parameter values are supplied at execution time.
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