<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:39:10 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-1284] Projection to object with string Id member yields CreateCannotDeserializeFromBsonTypeException</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1284</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;This appears to occur with any projection built with Builders&amp;lt;T&amp;gt;.Projection.&lt;/p&gt;

&lt;p&gt;The model class has an Id member which is a string, but no annotation attributes, for example:&lt;/p&gt;

&lt;p&gt;public class SomeClass { public string Id &lt;/p&gt;
{get;set;} public string Name {get;set;}
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;var result = _collection.FindOneAndUpdateAsync(filter, updateDef, new FindOneAndUpdateOptions&lt;br/&gt;
            {&lt;br/&gt;
                IsUpsert = true,&lt;br/&gt;
                Projection = Builders&amp;lt;T&amp;gt;.Projection.Expression(u =&amp;gt;  new &lt;/p&gt;
{ U.Id }
&lt;p&gt;),&lt;br/&gt;
                ReturnDocument = ReturnDocument.Before&lt;br/&gt;
            }).Result;&lt;/p&gt;

&lt;p&gt;The exception is thrown in StringSerializer.DeserializeValue.  In this case, the local variable bsonType is ObjectId, and _representation is String.&lt;/p&gt;

&lt;p&gt;Am I correct in thinking a check for this, followed by a call to bsonReader.ReadString(), would be the fix?&lt;/p&gt;

&lt;p&gt;If so, I&apos;d like to take the opportunity to build a Pull Request, but am unsure of the testing/submission guidelines, since the page linked to in the docs either  no longer exists or has moved from where GitHub points to.  Could you advise please?&lt;/p&gt;</description>
                <environment></environment>
        <key id="204687">CSHARP-1284</key>
            <summary>Projection to object with string Id member yields CreateCannotDeserializeFromBsonTypeException</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="kierenj">Kieren Johnstone</reporter>
                        <labels>
                    </labels>
                <created>Sun, 17 May 2015 06:33:18 +0000</created>
                <updated>Tue, 5 Apr 2016 00:28:45 +0000</updated>
                            <resolved>Tue, 2 Jun 2015 01:26:42 +0000</resolved>
                                    <version>2.0</version>
                                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="928460" author="kierenj" created="Mon, 1 Jun 2015 08:12:26 +0000"  >&lt;p&gt;Sorry for the delay - it was my mistake.  Effectively, I was doing an upsert with all properties in the $setOnInsert (by building the update document manually).  But I excluded the id property at the time because I was using an old version of Mongo (which threw an error with the upsert+$setOnInsert+id combo) and weirdly decided to just not set it.&lt;/p&gt;

&lt;p&gt;That meant an ObjectId was generated server-side, but then my Id field client-side was still just a &apos;string&apos;.&lt;/p&gt;

&lt;p&gt;I&apos;m quite certain then that this was just my mistake - now fixed by using the upsert+$sOI+id combo and the latest version of Mongo &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="921531" author="craiggwilson" created="Fri, 22 May 2015 13:03:01 +0000"  >&lt;p&gt;Kieren,&lt;/p&gt;

&lt;p&gt;Any update on this?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="916152" author="craiggwilson" created="Sun, 17 May 2015 17:53:00 +0000"  >&lt;p&gt;If you were to decorate your string property with a &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonRepresentation(BsonType.ObjectId)&amp;#93;&lt;/span&gt; attribute (or specified via code), this should work fine. But yes, you are right that the problem is we are expecting a string and receiving an ObjectId that was created by the server. &lt;/p&gt;

&lt;p&gt;What do your Id properties look like? Are they ObjectId&apos;s or a custom application identifer.&lt;/p&gt;</comment>
                            <comment id="916144" author="kierenj" created="Sun, 17 May 2015 15:17:45 +0000"  >&lt;p&gt;(I had removed _id from my upsert because I was seeing the error described in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-9958&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/SERVER-9958&lt;/a&gt; )&lt;/p&gt;</comment>
                            <comment id="916143" author="kierenj" created="Sun, 17 May 2015 15:10:11 +0000"  >&lt;p&gt;Ok, this occurs because I insert the object during an upsert which did not specify the _id field, leaving it to be automatically populated.  Then the deserialisation fails because it can&apos;t convert ObjectId to string.&lt;/p&gt;

&lt;p&gt;I think this is just my mistake, but before I close off, I&apos;d like to confirm this is expected behaviour?&lt;/p&gt;</comment>
                            <comment id="916116" author="kierenj" created="Sun, 17 May 2015 07:23:45 +0000"  >&lt;p&gt;In fact, oddly projection was just the first way I&apos;d tried to get a string Id out.  Even with no projection, the object fails to be deserialized.  This could be a mistake on my part..?&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|hs9f5r:</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>