C# driver Nullable Enum issue

480 views
Skip to first unread message

Kevin Lewis

unread,
Feb 9, 2011, 10:14:49 AM2/9/11
to mongodb-user
I've run across a problem storing nullable enumerations with the 10gen
C# driver, using latest source from github. It throws the following
exception on insert:
"EnumSerializer.Serialize cannot be used with nominal type:
System.Nullable`1[[NullableEnumTest.ItemType]]"

This gist is a very small console app reproduction of the issue:
https://gist.github.com/818600

It works as long as it is still set to null, but once given a value it
throws the exception. I plan to step through the source and see if I
can figure it out, but wanted to go ahead and post this here in case I
was missing something obvious.

Kevin Lewis

unread,
Feb 9, 2011, 11:29:53 AM2/9/11
to mongodb-user
EnumSerializer has a VerifySerializeTypes method that throws this
error if nominalType != actualType, and that is the case with a
nullable enum. I added an extra && clause to not throw if the
normalType is nullable, and it seems to insert just fine and pull back
out from the DB fine as well. I'm not sure what the repercussions
might be, or even why that check is there to begin with. Some of the
other serializers I spot checked do not have a similar check.

sridhar

unread,
Feb 9, 2011, 12:31:54 PM2/9/11
to mongodb-user
Nullable enum serialization is currently not supported in the C#. I
have filed a JIRA ticket (http://jira.mongodb.org/browse/CSHARP-167)
to add this support. thank you for providing the sample code.
> > was missing something obvious.- Hide quoted text -
>
> - Show quoted text -

Kevin Lewis

unread,
Feb 9, 2011, 2:03:45 PM2/9/11
to mongodb-user
I submitted a pull request with my proposed fix, and then noticed one
was already submitted. I closed my request and added a comment to the
Jira ticket pointing to https://github.com/mongodb/mongo-csharp-driver/pull/41

sridhar

unread,
Feb 10, 2011, 1:30:28 PM2/10/11
to mongodb-user
Thanks Kevin

On Feb 9, 11:03 am, Kevin Lewis <kevin.l.le...@gmail.com> wrote:
> I submitted a pull request with my proposed fix, and then noticed one
> was already submitted. I closed my request and added a comment to the
> Jira ticket pointing tohttps://github.com/mongodb/mongo-csharp-driver/pull/41
> > > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages