-
Type: Task
-
Resolution: Won't Fix
-
None
-
Affects Version/s: None
-
Component/s: None
-
Environment:Windows, Driver is version 2.1
Mongo DB Version is 3.0.1
*Location*: http://docs.mongodb.org/ecosystem/drivers/csharp/
*User-Agent*: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
*Referrer*: https://www.google.com/
*Screen Resolution*: 1920 x 1080
*repo*: docs-ecosystem
*source*: drivers/csharp
Windows, Driver is version 2.1 Mongo DB Version is 3.0.1 *Location*: http://docs.mongodb.org/ecosystem/drivers/csharp/ *User-Agent*: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36 *Referrer*: https://www.google.com/ *Screen Resolution*: 1920 x 1080 *repo*: docs-ecosystem *source*: drivers/csharp
Error condition is:
The driver tries to (de)serialize a mutlipolygon when it should be a polygon...
(note: point code works fine)
class in question has a property that is a polygon.
The data in the db has the loc field ... as a polygon ...the exception is listed below...
Offending class (identical to class using point)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Driver.GeoJsonObjectModel;
namespace WebApplicationFacebook.Helpers.Models
{
public class State
{
[BsonId(IdGenerator = typeof(ObjectIdGenerator))]
public ObjectId Id
[BsonElement("name")]
public string Name { get; set; }
[BsonElement("code")]
public string Code
[BsonElement("loc")]
public GeoJsonPolygon<GeoJson2DGeographicCoordinates> Loc { get; set; }
}
}
offending data .....
{
"_id" : ObjectId("536b0a143004b15885c91a20"),
"name" : "Wyoming",
"code" : "WY",
"loc" :
}
{"An error occurred while deserializing the Loc property of class WebApplicationFacebook.Helpers.Models.State: Invalid GeoJson type: 'MultiPolygon'. Expected: 'Polygon'."}System.AggregateException was unhandled by user code
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at WebApplicationFacebook.Services.MongoGeoJsonRepository.GetStates() in c:\Git\WebApplicationFacebook\WebApplicationFacebook\Services\MongoGeoJsonRepository.cs:line 747
at ServiceTest.MongoRepositoryTests.TestMethodStates() in c:\Git\WebApplicationFacebook\ServiceTest\MongoRepositoryTests.cs:line 147
InnerException: System.FormatException
HResult=-2146233033
Message=An error occurred while deserializing the Loc property of class WebApplicationFacebook.Helpers.Models.State: Invalid GeoJson type: 'MultiPolygon'. Expected: 'Polygon'.
Source=MongoDB.Bson
StackTrace:
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.ReplyMessageBinaryEncoder`1.ReadMessage()
at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.ReplyMessageBinaryEncoder`1.MongoDB.Driver.Core.WireProtocol.Messages.Encoders.IMessageEncoder.ReadMessage()
at MongoDB.Driver.Core.Connections.BinaryConnection.<ReceiveMessageAsync>d__15.MoveNext()
— 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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MongoDB.Driver.Core.WireProtocol.QueryWireProtocol`1.<ExecuteAsync>d__0.MoveNext()
— 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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MongoDB.Driver.Core.Servers.ClusterableServer.ServerChannel.<ExecuteProtocolAsync>d__24`1.MoveNext()
— 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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MongoDB.Driver.Core.Operations.FindOperation`1.<ExecuteAsync>d__2.MoveNext()
— 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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext()
— 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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperation>d__35`1.MoveNext()
— 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`1.GetResult()
at WebApplicationFacebook.Services.MongoGeoJsonRepository.<GetAllStates>d__75.MoveNext() in c:\Git\WebApplicationFacebook\WebApplicationFacebook\Services\MongoGeoJsonRepository.cs:line 755
InnerException: System.FormatException
HResult=-2146233033
Message=Invalid GeoJson type: 'MultiPolygon'. Expected: 'Polygon'.
Source=MongoDB.Driver
StackTrace:
at MongoDB.Driver.GeoJsonObjectModel.Serializers.GeoJsonObjectSerializerHelper`1.EnsureTypeIsValid(BsonDeserializationContext context)
at MongoDB.Driver.GeoJsonObjectModel.Serializers.GeoJsonObjectSerializerHelper`1.DeserializeBaseMember(BsonDeserializationContext context, String elementName, Int64 flag, GeoJsonObjectArgs`1 args)
at MongoDB.Driver.GeoJsonObjectModel.Serializers.GeoJsonPolygonSerializer`1.<>c_DisplayClass1.<DeserializeValue>b_0(String elementName, Int64 flag)
at MongoDB.Bson.Serialization.Serializers.SerializerHelper.DeserializeMembers(BsonDeserializationContext context, Action`2 memberHandler)
at MongoDB.Driver.GeoJsonObjectModel.Serializers.GeoJsonPolygonSerializer`1.DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.Serializers.ClassSerializerBase`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
InnerException:
.... test code is as follows:
public IMongoDatabase GetDataBase()
{
if (!localMongo.IsNullOrWhiteSpace())
{
if (!geoTest.IsNullOrWhiteSpace())
{
try
{
if (mongoClient == null)
return mongoClient.GetDatabase(geoTest);
}
catch (Exception exp)
}
}
throw new ApplicationException("Unable to create Mongo Client database is null");
}
public IMongoCollection<State> GetStatesCollection()
{ var db = GetDataBase(); var collection = db.GetCollection<State>("states"); return collection; } public async Task<List<State>> GetAllStates()
{
var stateCollection = GetStatesCollection();
List<State> states = new List<State>();
using (var cursor = await stateCollection.FindAsync(p => p.Name != ""))
{
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
foreach (var state in batch)
}
}
return states;
}
Reporter: George Celvi
E-mail: georgepcelvi@aol.com