<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:40 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-731] Cannot register my serizlizer in 1.8.1</title>
                <link>https://jira.mongodb.org/browse/CSHARP-731</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;This line&lt;/p&gt;

&lt;p&gt;BsonSerializer.RegisterSerializer(typeof(PSObject), new PSObjectSerializer());&lt;/p&gt;

&lt;p&gt;where PSObjectSerializer is my custom serializer for PSObject, throws an exception:&lt;/p&gt;

&lt;p&gt;There is already a serializer registered for type System.Management.Automation.PSObject.&lt;/p&gt;

&lt;p&gt;In 1.8 this code works fine. Is anything perhaps changed in ways of how custom serializers should be registered?&lt;/p&gt;</description>
                <environment></environment>
        <key id="72344">CSHARP-731</key>
            <summary>Cannot register my serizlizer in 1.8.1</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="5">Cannot Reproduce</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="nightroman">Roman Kuzmin</reporter>
                        <labels>
                    </labels>
                <created>Fri, 19 Apr 2013 09:09:38 +0000</created>
                <updated>Thu, 20 Mar 2014 19:13:19 +0000</updated>
                            <resolved>Thu, 20 Mar 2014 19:13:19 +0000</resolved>
                                    <version>1.8.1</version>
                                                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="520246" author="craiggwilson" created="Thu, 20 Mar 2014 19:13:19 +0000"  >&lt;p&gt;Ok.  Thanks Roman.  I&apos;m going to close this issue.  My apologies for never figuring out where the change happened.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="520228" author="nightroman" created="Thu, 20 Mar 2014 18:55:30 +0000"  >&lt;p&gt;I found a workaround. I register my serializers ASAP in several places. This is not neat perhaps but it works.&lt;/p&gt;</comment>
                            <comment id="520185" author="craiggwilson" created="Thu, 20 Mar 2014 18:12:14 +0000"  >&lt;p&gt;Roman,&lt;/p&gt;

&lt;p&gt;Is this still an issue?  I was never able to figure out what changed.  Were you able to workaround this issue from your side?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="317020" author="craiggwilson" created="Fri, 19 Apr 2013 14:42:04 +0000"  >&lt;p&gt;That is definitely an option, but I think the downsides to allowing the overriding of a serializer are too great.&lt;/p&gt;

&lt;p&gt;Let&apos;s take an example where someone is working with a custom class &quot;Person&quot;.  They have built a custom serializer and register it at some point in their application.  Sometime later, they add some code that inserts a bunch of people into the collection.  This code ran before the custom serializer was registered.  &lt;/p&gt;

&lt;p&gt;The outcome of this is horrible:  They have saved a bunch of Person entities with the default conventions that we built for them.  Then a custom serializer is registered.  All sorts of errors ensue because not all the saved Person entities look the same in MongoDB.  They could have different casings, different field names, different types, etc...  The custom Person serializer doesn&apos;t know how to deserialize this rogue information that was persisted prior to the serializer registration.&lt;/p&gt;

&lt;p&gt;Hence, our solution was to throw when you attempted to register a serializer for a type that already has one registered.  Sure, there are trade-offs, but we have elected to force a failure as soon as we see a problem as opposed to let your app continue to run and for you to fail later.&lt;/p&gt;

&lt;p&gt;It&apos;s perfectly fine for you to disagree with this decision, but it has been the defacto rule for serialization for as long as this code base has existed and changing it is not likely to happen anytime soon.&lt;/p&gt;

&lt;p&gt;Like I said, I&apos;m investigating what has changed to cause your codebase to need to register earlier.&lt;/p&gt;</comment>
                            <comment id="317016" author="nightroman" created="Fri, 19 Apr 2013 14:32:11 +0000"  >&lt;p&gt;From the top of my head I would recommend to think of simply allowing to override a serializer in RegisterSerializer instead of an extra check and throwing an exception on presence. This approach seems to be more flexible. After all an application on adding a serializer presumably really needs this serializer, not anything else that for some reason is already registered. As for adding it once, it&apos;s an application itself that should care, for example, like in my code precisely.&lt;/p&gt;

&lt;p&gt;All in all, it would be nice to be able to register different serializers for the same class. Practical use cases are presumably rare but I can see them possible. As an alternative, an extra method RegisterSerializer(..., bool force) could do this if &quot;force&quot; is true.&lt;/p&gt;</comment>
                            <comment id="317011" author="craiggwilson" created="Fri, 19 Apr 2013 14:22:31 +0000"  >&lt;p&gt;Agreed.  However, there is no good way for us to know that.  There are probably a lot of classes like that, but no way for us to tell the difference.&lt;/p&gt;

&lt;p&gt;A possible solution for us is to not automatically register a serializer and require a user to register/enable a serializer for every &quot;custom&quot; type it wants to use. Custom = type we don&apos;t have a pre-created serializer for.  PSObject would fall into this camp.  There are some obvious downsides to both strategies.&lt;/p&gt;

&lt;p&gt;Regardless, I&apos;m trying to pinpoint in your code using 1.8.1 where a serializer for PSObject is getting requested prior to the registration of its serializer.  &lt;/p&gt;</comment>
                            <comment id="317002" author="nightroman" created="Fri, 19 Apr 2013 14:09:12 +0000"  >&lt;p&gt;A thought of some not standard but possible scenarios. You cannot build any useful default map for a PSObject because it basically has no standard properties in C# sense, they are all dynamic. Only a custom serializer will do for such a class. So that if for some reason (even a mistake in a bad 3rd party module, not even the app itself) an application tried to serialize PSObject before registering a proper serializer then it is not possible to add a proper serializer at all by any means.&lt;/p&gt;</comment>
                            <comment id="316998" author="craiggwilson" created="Fri, 19 Apr 2013 14:00:39 +0000"  >&lt;p&gt;Not disagreeing.  I would call it a regression as well.  Just trying to figure out what is different.&lt;/p&gt;</comment>
                            <comment id="316997" author="nightroman" created="Fri, 19 Apr 2013 13:58:35 +0000"  >&lt;p&gt;As I wrote, in 1.8 my application works fine. The same its code (a trivial test) fails in 1.8.1. I would call this a regression.&lt;/p&gt;</comment>
                            <comment id="316993" author="craiggwilson" created="Fri, 19 Apr 2013 13:53:44 +0000"  >&lt;p&gt;Before use = before the use of the object with a custom serializer.  In other words, you can use the bson library as long as, before using PSObject, you have registered its serializer.  A little confusing, but perhaps I can explain better based on how we handle this.&lt;/p&gt;

&lt;p&gt;The serializer map is a global static object.  When a serializer is necessary for PSObject, we consult this map.  If we find one registered, we use it.  Otherwise, we&apos;ll attempt to build one automatically and register it.  If you attempt to register a serializer that is already present in the map, we&apos;ll throw an exception.  The reason for this is obvious.  It would be horrible for your application to serializer PSObject one way for a while and then switch over to using a new serializer half-way through.&lt;/p&gt;

&lt;p&gt;So, as I alluded to above, the only way this could be happening is if something was requesting a serializer for PSObject before you registered the PSObjectSerializer.&lt;/p&gt;

&lt;p&gt;I&apos;m still a little confused by your statement that this is a regression.  What version of the driver were you using before where this was not an issue?  We literally haven&apos;t changed this behavior in a very long time.&lt;/p&gt;</comment>
                            <comment id="316980" author="nightroman" created="Fri, 19 Apr 2013 13:41:05 +0000"  >&lt;p&gt;To understand the problem better try to add a unit test for RegisterSerializer. Correct me if I am wrong but there is no one. You will see a problem I am talking about. Your test should be called ASAP before any use of bson library. This is at least inconvenient. Are such conventions and difficulties really necessary for bson users now?&lt;/p&gt;</comment>
                            <comment id="316971" author="nightroman" created="Fri, 19 Apr 2013 13:22:33 +0000"  >&lt;p&gt;I tried to register my serializer before connecting. This fixes the problem, I can live with this. But this is still a regression and going backwards. An application had an ability to register some serializers on demand. Now this ability has gone. This forces an application to register all possible serializers ASAP. In some cases this might be not even possible. Imagine a use case when an application loads child modules with serizlizers dynamically and at the start it does not even know which modules are going to be loaded in a session.&lt;/p&gt;

&lt;p&gt;Thank you for the tip. My particular problem seems to be solved. But please think of my remarks.&lt;/p&gt;
</comment>
                            <comment id="316964" author="nightroman" created="Fri, 19 Apr 2013 13:11:14 +0000"  >&lt;p&gt;I call BsonSerializer.RegisterSerializer(typeof(PSObject), new PSObjectSerializer())&lt;br/&gt;
on the first need and once. The code is&lt;br/&gt;
&lt;a href=&quot;https://github.com/nightroman/Mdbc/blob/master/Src/PSObjectSerializer.cs&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/nightroman/Mdbc/blob/master/Src/PSObjectSerializer.cs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also described how to reproduce the problem (all you need is to have PowerShell installed). If you need more details let me know.&lt;/p&gt;</comment>
                            <comment id="316958" author="craiggwilson" created="Fri, 19 Apr 2013 12:53:53 +0000"  >&lt;p&gt;Hi Roman,&lt;/p&gt;

&lt;p&gt;Could you indicate where you are attempting to register this serializer in the lifecycle of your application.  Perhaps post your code... Nothing significant related to this changed between 1.8 and 1.8.1.  Registering serializers needs to happen before any attempt to use the bson library, which includes connecting to the server.  &lt;/p&gt;

&lt;p&gt;Regarding 2012, yes, we need to fix that.  Changing the top 2 lines in the .sln file to 11.00 and 2010 respectively should allow it to be opened.&lt;/p&gt;</comment>
                            <comment id="316876" author="nightroman" created="Fri, 19 Apr 2013 09:33:20 +0000"  >&lt;p&gt;I would debug this but you moved to VS 2012 (btw, the file name CSharpDriver-2010.sln is misleading) and I do not use VS 2012 yet.&lt;/p&gt;

&lt;p&gt;In order to reproduce the issue you can use this PowerShell module&lt;br/&gt;
&lt;a href=&quot;https://github.com/nightroman/Mdbc&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/nightroman/Mdbc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;import it and invoke, for example, this script&lt;br/&gt;
&lt;a href=&quot;https://github.com/nightroman/Mdbc/blob/master/Tests/Test-About.ps1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/nightroman/Mdbc/blob/master/Tests/Test-About.ps1&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrnd9z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>50102</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>