<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:41:05 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-1926] Registered Convention Not Applied</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1926</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I have created a Convention in my Asp.Net MVC application to map between using a string Id property in my classes and a BsonId in the database. I register this convention at startup via the Application_Start method in my Global.asax: &lt;/p&gt;

&lt;p&gt;ConventionRegistry.Register(&quot;Custom Conventions&quot;, new ConventionPack &lt;/p&gt;
{ new StringObjectIdConvention()}
&lt;p&gt;, t =&amp;gt; t.FullName.StartsWith(&quot;MyProjectName.&quot;));&lt;/p&gt;

&lt;p&gt;The convention works as expected but when deployed to server it will fail to apply after some amount of time (the error will occur when retrieving data from the database and I will get an &quot;System.FormatException: An error occurred while deserializing the Id property of class &quot;ClassName&quot;: Cannot deserialize a &apos;String&apos; from BsonType &apos;ObjectId&apos;&quot;.). This can sometimes be immediately after deployment or after a seemingly random amount of time. In order to get the convention to work again I have to restart the App Pool. &lt;/p&gt;

&lt;p&gt;Is there anything I am doing wrong that could cause this behavior? Is there any way I can check if the convention is still registered when the error occurs?&lt;/p&gt;

&lt;p&gt;As an aside, I am also using Hangfire with Mongo as it&apos;s storage in the same web application (using the official Hangfire Mongo driver). Although my registered convention should not apply to to the Hangfire storage (since I apply the filter when registering) is there any chance that this could somehow be interfering? When Hangfire has been disabled I have not noticed the error.&lt;/p&gt;</description>
                <environment></environment>
        <key id="355947">CSHARP-1926</key>
            <summary>Registered Convention Not Applied</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="mgeorghion@russellinvestments.com">Michael Georghion</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Tue, 21 Feb 2017 18:17:10 +0000</created>
                <updated>Fri, 5 Apr 2019 13:58:07 +0000</updated>
                            <resolved>Fri, 13 Oct 2017 18:17:26 +0000</resolved>
                                    <version>2.4</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1514404" author="rstam" created="Thu, 2 Mar 2017 15:18:13 +0000"  >&lt;p&gt;I&apos;m not sure what&apos;s going on. A stack trace of any exception you are getting might provide helpful information.&lt;/p&gt;

&lt;p&gt;You want to make sure that your custom StringObjectIdConvention only applies to string fields that hold an ObjectId, not to all string fields.&lt;/p&gt;

&lt;p&gt;You also want to make sure that your convention is registered &lt;b&gt;very&lt;/b&gt; early in your application, certainly &lt;b&gt;before&lt;/b&gt; any database operations are performed that might cause some automatic serialization configuration to occur before your convention has been registered.&lt;/p&gt;

&lt;p&gt;I&apos;m unfamiliar with Hangfire, but according to its Nuget information it depends on the C# driver. Since it is running in the same process it will share serialization configuration information with your application. Since you check for the type name starting with &quot;MyProjectName.&quot; in your convention registration this should not be a problem.&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|hsvalr:</customfieldvalue>

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