【问题标题】:Guid is causing a format exceptionGuid 导致格式异常
【发布时间】:2018-01-23 11:00:51
【问题描述】:

我正在尝试设置 RavenDb 3.5 和 NServiceBus 6。在我发送我在 NServiceBus 端点中设置的 saga 之后,我输入了一个处理程序。一旦这个处理程序完成,我得到这个错误:

System.FormatException: Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。

我的代码:

public static class AutoFacConfig
{
    public static IContainer ConfigureAutofac()
    {
        var builder = new ContainerBuilder();

        var resourceManagerId = new Guid("6c9abcbb-c7ca-4a67-a149-5142f633f535");

        var dtcRecoveryBasePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
        var recoveryPath = Path.Combine(dtcRecoveryBasePath, "NServiceBus.RavenDB", resourceManagerId.ToString());

        builder.Register(x =>
        {
            var store = new DocumentStore
            {
                ConnectionStringName = "RavenDB",
                ResourceManagerId = resourceManagerId,
                TransactionRecoveryStorage = new LocalDirectoryTransactionRecoveryStorage(recoveryPath)
            };
            store.DefaultDatabase = "MyDB";
            store.Initialize();
            store.Conventions.IdentityPartsSeparator = "-";
            return store;
        })
            .As<IDocumentStore>()
            .SingleInstance();

        builder.Register<IFilesStore>(x =>
        {
            var fileStore = new FilesStore()
            {
                Url = "http://localhost:40000",
                DefaultFileSystem = "MyFS",
            }.Initialize();
            return fileStore;
        }).SingleInstance();

        return builder.Build();
    }
}

在传奇中:

    protected override void ConfigureHowToFindSaga(SagaPropertyMapper<FileToOrderSagaData> mapper)
    {
        mapper.ConfigureMapping<StartFileToOrderSagaCommand>(m => m.DataId)
            .ToSaga(s => s.DataId);
    }

    public async Task Handle(StartFileToOrderSagaCommand message, IMessageHandlerContext context)
    {
        // Do Validation ValidateXmlCommand
        Data.DataId = message.DataId;
        await context.Send<ValidateXmlCommand>( x => { x.Filename = message.Filename; x.CustomerId = message.CustomerId; });
    }

这是堆栈跟踪:

at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
at System.Guid..ctor(String g)
at Raven.Client.Converters.GuidConverter.ConvertTo(String value) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Converters\GuidConverter.cs:line 51
at Raven.Client.Document.GenerateEntityIdOnTheClient.SetPropertyOrField(Type propertyOrFieldType, Object entity, Action`1 setIdentifier, String id) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\GenerateEntityIdOnTheClient.cs:line 170
at Raven.Client.Document.GenerateEntityIdOnTheClient.TrySetIdentity(Object entity, String id) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\GenerateEntityIdOnTheClient.cs:line 143
at Raven.Client.Document.InMemoryDocumentSessionOperations.<GenerateDocumentKeyForStorageAsync>d__99.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 833
--- 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 Raven.Client.Document.InMemoryDocumentSessionOperations.<StoreAsyncInternal>d__96.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Document\InMemoryDocumentSessionOperations.cs:line 803

有帮助吗?

【问题讨论】:

  • 您的代码在哪里得到错误?
  • 似乎是 RavenDB 问题,您认为这是否相关,因为您在代码中都使用了“IdentityPartsSeparator”:stackoverflow.com/questions/26787884/…
  • @HadiEskandari 它是相关的,它解决了我的问题。谢谢哈迪! :)
  • @solid_luffy 很高兴它为你解决了 :)

标签: c# ravendb nservicebus


【解决方案1】:

删除后

        store.Conventions.IdentityPartsSeparator = "-";

问题已解决。 有关更多信息,请参阅上面 HadiEskandari 的评论和此链接:Exception in RavenDB.SagaPersister.Save, "Guid should contain 32 digits with 4 dashes". Guid is empty in Raven

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2018-09-20
    • 2014-01-09
    • 1970-01-01
    相关资源
    最近更新 更多