|
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
{ get; set; }
[BsonElement("name")]
public string Name { get; set; }
[BsonElement("code")]
public string Code
{ get; set; }
[BsonElement("loc")]
public GeoJsonPolygon<GeoJson2DGeographicCoordinates> Loc { get; set; }
}
}
offending data .....
{
"_id" : ObjectId("536b0a143004b15885c91a20"),
"name" : "Wyoming",
"code" : "WY",
"loc" :
{
"type" : "Polygon",
"coordinates" : [
[
[
-108.6213129999998700,
45.0002769999999830
],
[
-104.0576969999999500,
44.9973800000001350
],
[
-104.0532489999999900,
41.0014060000000880
],
[
-111.0467229999999900,
40.9979589999999800
],
[
-111.0551989999998900,
45.0013210000000750
],
[
-108.6213129999998700,
45.0002769999999830
]
]
]
}
}
{"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)
{
mongoClient = new MongoClient(localMongo);
}
return mongoClient.GetDatabase(geoTest);
}
catch (Exception exp)
{
log.Error("getDataBase failed", 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)
{
states.Add(state);
}
}
}
return states;
}
Reporter: George Celvi
E-mail: georgepcelvi@aol.com
|