Mongo db bsonerializationexception при использовании iaggregatefluentextensions.graphlookup () с гиидамиC#

Место общения программистов C#
Ответить
Anonymous
 Mongo db bsonerializationexception при использовании iaggregatefluentextensions.graphlookup () с гиидами

Сообщение Anonymous »

Я храню деревья узлов в (локальной) базе данных Mongo, используя GUID в качестве EntityID и ParentityID для каждого узла. Я пытаюсь получить узлы, используя iaggregatefluentextensions.graphlookup (). Призыв к graphlookup () бросает: < /p>

mongodb.bson.bsonserializationexception: Guidserializer не может дать детериализу GUID, когда руководство не указано. < /P>
< /blockquote>
Почему оно бросает это исключение? Обработка GUID настроена для V3 в соответствии с приведенным ниже кодом. Он работал над хранением и получением других типов в той же базе данных, которые имеют гииды.

Код: Выделить всё

public class TestEntity
{
[BsonId]
public ObjectId Id { get; set;}

[BsonGuidRepresentation(GuidRepresentation.Standard)]
public Guid EntityId { get; set; }

[BsonGuidRepresentation(GuidRepresentation.Standard)]
public Guid ParentEntityId { get; set; }

public string Name { get; set; }
}
< /code>
Вот упрощенная версия кода репозитория, которая бросает исключение в строке graphlookup (). < /p>
public async Task DoGraphLookup()
{
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));

MongoClientSettings mongoClientSettings = MongoClientSettings.FromConnectionString("mongodb://HOSTNAME:27017");
MongoClient mongoClient = new MongoClient(mongoClientSettings);

IMongoDatabase database = mongoClient.GetDatabase("DATABASENAME");

IMongoCollection collection = database.GetCollection("COLLECTIONNAME");

List result = await collection
.Aggregate()
//.Match(c => c.Name == "MatchName")
.GraphLookup(
from: collection,
startWith: $"${nameof(TestEntity.EntityId)}",
connectFromField: nameof(TestEntity.ParentEntityId),
connectToField: nameof(TestEntity.EntityId),
@as: "BreadCrumb",
depthField: "order")
.ToListAsync();

return result;
}
< /code>
Я использую C# .net Core 3.1, с этими пакетами Nuget в моем проекте: < /p>
MongoDB.Bson 2.13.1
MongoDB.Driver 2.13.1
MongoDB.Driver.Core 2.13.1
< /code>
db выглядит так: < /p>
Содержимое базы данных < /p>
--- РЕДАКТИРОВАТЬ ---
Трассировка стека исключений: < /p>

myapplication.repositories.treeofnodesrepository.dographlookup:
/> Сообщение об ошибке:
mongodb.bson.bsonserializationexception: Guidserializer не может двойровать GUID, когда руководство не указано.  Контекст, BsondeserializationArgs args)
at mongodb.beson.serialization.ibsonserializerextensions.deserialize [TVALUE] (IBSONSERIALIZER1 serializer, BsonDeserializationContext context) at MongoDB.Bson.Serialization.Serializers.ObjectSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer< /code> 1 Serializer, BsondeserializationContext Context)
at mongodb.beson.serialization.serializers.dynamicdocumentbaseSerializer1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) at MongoDB.Bson.Serialization.Serializers.SerializerBase< /code> 1.mongodb.beson.serialization.ibsonserializer.deserialize (BsondeserializationContext Context, bsondeserializationArgs args)
at mongodb.besson.serialization.serializers.objectserializer.deserializeScripriMistististizationValue BsondeserializationArgs args)
at mongodb.beson.serialization.serializers.objectserializer.deserialize (bsondeserialization context, bsondeserializationArgs args)
at Mongodb.bson.serialization.ibsoneserializerextensions.deserialize [TVALUE] (IBSONSERIALIZER1 serializer, BsonDeserializationContext context) at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase< /code> 2.deserialize (bsondeserializationcontext context, bsondeserializationargs args)
at mongodb.besson.serialization.ibsoneserializerextensions.deserialize [TVALUE] (IbSonserializer1 serializer, BsonDeserializationContext context) at MongoDB.Driver.Core.Operations.AggregateOperation< /code> 1.cursordeserializer.deserialize (bsondeserializationcontext context, bsondeserializationArgs args)
at mongodb.besson.serialization.ibsoneserializerextensions.deserialize [tvalue] (Ibsonseriation1 serializer, BsonDeserializationContext context) at MongoDB.Driver.Core.Operations.AggregateOperation< /code> 1.aggregateresultdeserializer.deserialize (bsondeserialization context, bsondeserializationargs args)
at mongodb.besson.serialization.ibsonerializerextensions.deserialize [tvalue] (ibsonseriatizer1 serializer, BsonDeserializationContext context) at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol< /code> 1.processResponse (connectionId ConnectionId, CommandMessage responseMessage)
at mongodb.driver.core.wireprotocol.commandusingCommandMessageWireProtocol1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol< /code> 1 Протокол, сеанс ICORESESSION, CancellationToken CancellationToken)
at mongodb.driver.core.operations.retryablereadoperationexecutor.executeasync [tresult] (inretryableDeadoperation1 operation, RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.ReadCommandOperation< /code> 1.executeasync (контекст retryabledeadContext, CancellationToken CancellationToken)
at mongodb.driver.core.operations.aggregateoperation1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.AggregateOperation< /code> 1.ExecuteAsync (привязка к ireadbinding, DecellationToken CancellationToken)
at mongodb.driver.operationexecutor.executereadoperationAsync [tresult] (Ireadbinding Binding, Ireadoperation1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.executereadoperationAsync [treSult] (IclientsessionHandle Session, имени

Код: Выделить всё

1 operation, ReadPreference readPreference, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.AggregateAsync [tresult] (IclientsessionHandle Session, PipelinedEfinition

Код: Выделить всё

2 pipeline, AggregateOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl
1.UsingImplicitSessionAsync[TResult](Func

Код: Выделить всё

2 funcAsync, CancellationToken cancellationToken) at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource< /code> 1 Источник, CancellationToken CancellationToken)
at myApplication.repositories.treeofnodesrepository.dographlookup () в c: \ source \ saasem \ codegenerator \ tests \ codegenerator.applicationStore.tests \ RepoSitories \ GraphCclookeptest.cs:  line 45
at NUNIT.FrameWork.Internal.taskawaitAdapter.genericAdapter1.BlockUntilCompleted() at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func< /code> 1 invoke)
at nunit.framework.internal.commands.testmethodcommand.runtestmethod (контекст testexecutioncontext)
at nunit.framework.internal.commands.testmethodcommand.execut > в Nunit.framework.internal.execution.simpleworkitem1.b__0(Object _) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at NUnit.Framework.Internal.ContextUtils.DoIsolated(ContextCallback callback, Object state) at NUnit.Framework.Internal.ContextUtils.DoIsolated[T](Func
1 func)
at nunit.framework.internal.execution.simpleworkitem.performwork ()


Подробнее здесь: https://stackoverflow.com/questions/688 ... ons-graphl
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»