<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:47 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-94] Structure support </title>
                <link>https://jira.mongodb.org/browse/CSHARP-94</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I have noticed that latest C# Driver has some failing tests, for structure support.&lt;br/&gt;
I have tried to fix it by myself, but I hit some framework limitations.&lt;br/&gt;
So, here they are, to save your&apos;s time:&lt;br/&gt;
1. IL/Expression Setters inside BsonMemberMap are not working for structs, because structs are passed by value (and not by ref)&lt;br/&gt;
2. I have tried to switch setter syntax from Action&amp;lt;object, object&amp;gt; to custom delegate that looks like Action&amp;lt;ref object, object&amp;gt;, but I came across FW limitations&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Dynamic method  (used for IL code) does not support not REF, nor OUT modifiers&lt;/li&gt;
	&lt;li&gt;I haven&apos;t found how to use LINQ.Expressions builder, to support REF or OUT modifiers&lt;/li&gt;
	&lt;li&gt;There is a way, to use Func&amp;lt;object, object, object&amp;gt; modifiers, that returns modified struct each time, but IMO it would be painful for GC&lt;/li&gt;
&lt;/ul&gt;
</description>
                <environment>Win7 x64, latest C# Driver trunk</environment>
        <key id="13643">CSHARP-94</key>
            <summary>Structure support </summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="-1">Unassigned</assignee>
                                    <reporter username="valera_kolupaev">Valera Kolupaev</reporter>
                        <labels>
                    </labels>
                <created>Mon, 8 Nov 2010 09:42:57 +0000</created>
                <updated>Fri, 20 Nov 2020 15:29:05 +0000</updated>
                            <resolved>Fri, 20 Nov 2020 15:29:05 +0000</resolved>
                                                                    <component>Feature Request</component>
                                        <votes>14</votes>
                                    <watches>16</watches>
                                                                                                                <comments>
                            <comment id="3499801" author="jeff.yemin" created="Fri, 20 Nov 2020 15:28:46 +0000"  >&lt;p&gt;For anyone still watching this issue:&#160; the driver does now support immutable structures and mutable structures that have a constructor annotated with &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonConstructor&amp;#93;&lt;/span&gt;&lt;/tt&gt;.&#160; As&#160;this covers the most common use cases for structures, we&apos;re going to close this issue.  &lt;/p&gt;

&lt;p&gt;If anyone needs further support for structures, please open a new Jira issue.&lt;/p&gt;</comment>
                            <comment id="634364" author="jayb" created="Thu, 26 Jun 2014 00:19:43 +0000"  >&lt;p&gt;Any updates on this?&lt;/p&gt;</comment>
                            <comment id="488094" author="jcaldicott" created="Mon, 27 Jan 2014 14:58:51 +0000"  >&lt;p&gt;That would be fine for my use-case, we already have constructors like that.  I guess as long as the exception message you get when you try to serialize structs mentions the new convention, then it&apos;s still discoverable.&lt;/p&gt;

&lt;p&gt;Thanks for the prompt attention!&lt;/p&gt;</comment>
                            <comment id="488072" author="craiggwilson" created="Mon, 27 Jan 2014 13:55:22 +0000"  >&lt;p&gt;Hey Justin,&lt;br/&gt;
  Thanks for the feedback.  I said immutability, but that&apos;s not exactly true.  What I meant to convey is that all values that are persisted to MongoDB would need a parameter in the constructor.  In fact, it would be possible to have all your values be mutable as long as there was a constructor argument for each of properties you want to persist.  In your case, simply keeping a dirty flag around is fine because you wouldn&apos;t persist your dirty flag to MongoDB.&lt;/p&gt;

&lt;p&gt;Hope that clears it up...  I&apos;ll work on a convention to map the properties and constructor for structs automatically.  I&apos;m not sure if we&apos;ll make it part of the default convention pack or require you to register it yourself.  Making it part of the default conventions could break some people relying on the fact that we don&apos;t map structs.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="488022" author="jcaldicott" created="Mon, 27 Jan 2014 10:49:32 +0000"  >&lt;p&gt;Thanks for the quick response Craig.  I&apos;ve managed to work around it by creating a custom serializer for our structs.  It&apos;s based on something I saw in a Google forum: &lt;a href=&quot;https://gist.github.com/bluebirdtech/1d94a88680594406909c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/bluebirdtech/1d94a88680594406909c&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are three downsides to this that I see:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;I have to maintain this code going forward (granted it&apos;s quite small)&lt;/li&gt;
	&lt;li&gt;I&apos;m not able to make use of the conventions that we&apos;ve applied via the ConventionRegistry.  I have to explicitly create the same behaviour separately for structs.  This means that the code is specific to our use-case and not reusable.&lt;/li&gt;
	&lt;li&gt;I have to add &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonSerializer(typeof(StructBsonSerializer))&amp;#93;&lt;/span&gt; to structs.  Possible to forget, but mostly the issue is that I&apos;d like to be able to keep the project that has our business objects free of the reference to using MongoDB.Bson.  This is going to be used on mobile devices, where it will be serializing using NewtonSoft.Json.  (Though I&apos;m interested to look into using MongoDB.Bson for consistency across our system.)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Regarding your approach, being able to create a convention would be great.  I&apos;m not so keen on forcing immutability.  I agree that in most cases it&apos;s a best practise, but it&apos;s not always possible.  For example, with our on device data store we&apos;re able to mark changed objects, then either commit or discard the changes.  Discarding the changes requires to update the existing object.&lt;/p&gt;</comment>
                            <comment id="487976" author="craiggwilson" created="Mon, 27 Jan 2014 01:14:56 +0000"  >&lt;p&gt;I need to confer with my colleague, but a little testing shows that the work done in &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-476&quot; title=&quot;Support parameterized constructors on deserialization&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-476&quot;&gt;&lt;del&gt;CSHARP-476&lt;/del&gt;&lt;/a&gt; enables this to work with some minor tweaks.  There are a couple of caveats, although if you are using structs correctly, shouldn&apos;t be an issue.    &lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;As is always the case, structs are meant to be immutable.  As such, you&apos;ll only be able to use structs that take all their values as construct arguments.  Setters won&apos;t work.&lt;/li&gt;
	&lt;li&gt;You&apos;ll either need to manually map all structs or create a convention to do so.  We could probably be convinced to enable that convention by default for structs.  It would basically map all read-only properties where a correlating constructor parameter matches the property name (possibly differing in case).&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Let me know if this sounds satisfactory and I&apos;ll begin working on a solution, hopefully in our next release.&lt;/p&gt;</comment>
                            <comment id="487899" author="jcaldicott" created="Sun, 26 Jan 2014 09:26:05 +0000"  >&lt;p&gt;.NET structs aren&apos;t supported at all with Mongo?  This does seem like core functionality to be missing.  Does anyone have a workaround that doesn&apos;t involve making the struct a class?&lt;/p&gt;</comment>
                            <comment id="422258" author="christina" created="Tue, 10 Sep 2013 22:52:41 +0000"  >&lt;p&gt;I can&apos;t believe this is marked as minor priority... There is no easy workaround and this is important functionality that you are missing!&lt;/p&gt;</comment>
                            <comment id="371357" author="jasonfry89" created="Mon, 1 Jul 2013 04:16:06 +0000"  >&lt;p&gt;I agree with Michael and Gustavo - this is critical functionality that is missing from this driver. I too have classes with nested structs that will all need to be converted to classes. Please prioritize this bug!&lt;/p&gt;</comment>
                            <comment id="252004" author="ggondim" created="Mon, 28 Jan 2013 18:54:36 +0000"  >&lt;p&gt;I was using MongoDB applied to a DDD project, that used the &quot;Value Objects&quot; as structs inside classes. After the exception, it confused me and forced me to believe the problem was with interface deserialization (which is another problem in the driver). After questions in StackOverflow and after implement custom serialziers for the interfaces, I have found this issue.&lt;/p&gt;

&lt;p&gt;I rolled back the project to inicial state (without custom serializers) and changed the struct types to classes. It worked. But, in some cases I REALLY will need the types be passed as a value, not as a reference.&lt;/p&gt;

&lt;p&gt;This is issue should be priorized, and considered a major implementation. I am trying to help you with this and another to issues (interfaces deserialization and LinQ projections).&lt;/p&gt;

&lt;p&gt;Please, someone give some attention to this issue.&lt;/p&gt;</comment>
                            <comment id="237219" author="mbertelsen" created="Fri, 11 Jan 2013 15:17:26 +0000"  >&lt;p&gt;I do not understand that this is considered as a Minor bug, and is not resolved? &lt;br/&gt;
I have many lists with structs that I would like to serialize. What about vectors, complex numbers etc?&lt;/p&gt;</comment>
                            <comment id="87088" author="travislaborde" created="Thu, 9 Feb 2012 22:05:00 +0000"  >&lt;p&gt;In the meantime, it would perhaps be easy/quick to add something preventing these from even going INTO the database.  Since you won&apos;t be able to get them back out again without modifying your classes.  Sort of going with the &quot;fail fast&quot; mentality.  Let the developer know as soon as possible that this isn&apos;t going to work out...&lt;/p&gt;</comment>
                            <comment id="20108" author="rstam" created="Mon, 8 Nov 2010 14:11:43 +0000"  >&lt;p&gt;Thanks for the information. We probably are not going to implement support for structs until after the 1.0 release.&lt;/p&gt;</comment>
                            <comment id="20104" author="valera_kolupaev" created="Mon, 8 Nov 2010 09:49:22 +0000"  >&lt;p&gt;Here is a recipe, for ref parameters in LINQ Expressions:&lt;br/&gt;
&lt;a href=&quot;http://efreedom.com/Question/1-1272454/Generate-Dynamic-Method-Set-Field-Struct-Instead-Using-Reflection&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://efreedom.com/Question/1-1272454/Generate-Dynamic-Method-Set-Field-Struct-Instead-Using-Reflection&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|hre147:</customfieldvalue>

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