When an integer property of a typed document stored in mongo is selected, and a subsequent distinct operation is performed the following exception occurs:
Test method MongoInvestigation.Test.UnitTest1.TestMethod1 threw exception:
System.FormatException: Cannot deserialize a 'Int32' from BsonType 'Document'.
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MongoInvestigation.Test.UnitTest1.<TestMethod1>d__2.MoveNext() in C:\GITProjects\MongoInvestigation\MongoInvestigation.Test\UnitTest1.cs:line 37
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Please see attached code demonstrating the failure.