EventFlow NETCore 8 - ReadModelByIdQuery 从数据库解析数据无效

问题描述 投票:0回答:1

我有一个带有 EventFlow 的 WebApi。它在 .NET Core 2.1 上运行良好,但我将其升级到 .NET 8。并且出现了问题。当我尝试使用 ReadModelByIdQuery 应用程序抛出 InvalidOperationException 时。看起来 SqlClient 找不到 CorrelationId 列,但是当我在 .NET 2.1 上使用它时,它工作正常。有人对此有任何想法吗?

Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.

System.InvalidOperationException: Error parsing column 6 (CorrelationId=CH - String)
 ---> System.TypeLoadException: Could not load type 'SqlGuidCaster' from assembly 'System.Data.SqlClient, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.
   at System.Data.SqlTypes.SqlTypeWorkarounds.SqlGuidCtor(Byte[] value, Boolean ignored)
   at System.Data.SqlClient.TdsParser.TryReadSqlValueInternal(SqlBuffer value, Byte tdsType, Int32 length, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly)
   at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn)
   at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
   at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
   at System.Data.SqlClient.SqlDataReader.get_Item(Int32 i)
   at Deserialize5ef26d5d-2eb7-4a7d-9c32-0119a057d718(IDataReader)
   --- End of inner exception stack trace ---
   at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value)
   at Deserialize5ef26d5d-2eb7-4a7d-9c32-0119a057d718(IDataReader)
   at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command)
   at EventFlow.Sql.Connections.SqlConnection`3.<>c__DisplayClass16_0`1.<<WithConnectionAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at EventFlow.Core.TransientFaultHandler`1.TryAsync[T](Func`2 action, Label label, CancellationToken cancellationToken)
   at EventFlow.Sql.Connections.SqlConnection`3.QueryAsync[TResult](Label label, CancellationToken cancellationToken, String sql, Object param)
   at EventFlow.MsSql.ReadStores.MssqlReadModelStore`1.GetAsync(String id, CancellationToken cancellationToken)
   at EventFlow.Queries.ReadModelByIdQueryHandler`2.ExecuteQueryAsync(ReadModelByIdQuery`1 query, CancellationToken cancellationToken)
   at EventFlow.Queries.QueryProcessor.ProcessAsync[TResult](IQuery`1 query, CancellationToken cancellationToken)
   at WebApplicationforSG.Controllers.DictionaryController.GetById(String id)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

程序.cs

 builder.Services.AddEventFlow(opt =>
 {
     opt.AddAspNetCore();
     opt.Configure(c =>
     {
         c.ThrowSubscriberExceptions = true;
         c.IsAsynchronousSubscribersEnabled = true;
     });
     opt.ConfigureMsSql(MsSqlConfiguration.New
         .SetConnectionString(connectionString)
         .SetTransientRetryCount(2));
     opt.AddDefaults(Assembly.GetExecutingAssembly());
     opt.UseConsoleLog();
     opt.UseMssqlEventStore();  
     opt.UseMssqlReadModel<DictionaryEntryReadModel>();   
     opt.RegisterServices(r =>
     {
         r.RegisterGeneric(typeof(ISearchableReadModelStore<>), typeof(EfSearchableReadStore<>));
         r.Register(x => new EmployeeVerificationRequestReadModelLocator());
     });

 });

ReadModel 类

 public class DictionaryEntryReadModel : IReadModel,
     IAmReadModelFor<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryCreatedEvent>,
     IAmReadModelFor<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryRemovedEvent>,
     IAmReadModelFor<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryEditedEvent>
 {
     [MsSqlReadModelIdentityColumn]
     [DatabaseGenerated(DatabaseGeneratedOption.None)]
     [Key]
     [MaxLength(52)]
     public string AggregateId { get; set; }

     [MsSqlReadModelVersionColumn] 
     public int Version { get; set; }

     public string CustomId { get; set; }
     public DictionaryType EntryType { get; set; }
     public string EntryValue { get; set; }
     public string EntryRegExp { get; set; }
     public Guid CorrelationId { get; set; }
    

     public void Apply(IReadModelContext context,
         IDomainEvent<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryCreatedEvent> domainEvent)
     {
         AggregateId = domainEvent.AggregateIdentity.Value;
         CustomId = domainEvent.AggregateEvent.CustomId;
         EntryType = domainEvent.AggregateEvent.EntryType;
         EntryValue = domainEvent.AggregateEvent.EntryValue;
         EntryRegExp = domainEvent.AggregateEvent.EntryRegExp;
         CorrelationId = domainEvent.AggregateEvent.CorrelationId;
     }

     public void Apply(IReadModelContext context, IDomainEvent<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryRemovedEvent> domainEvent)
     {
         context.MarkForDeletion();
     }

     public void Apply(IReadModelContext context, IDomainEvent<DictionaryEntryAggregate, DictionaryEntryId, DictionaryEntryEditedEvent> domainEvent)
     {
         CustomId = domainEvent.AggregateEvent.CustomId;
         EntryValue = domainEvent.AggregateEvent.EntryValue;
         EntryRegExp = domainEvent.AggregateEvent.EntryRegExp;
     }
 }

桌子

TABLE [dbo].[ReadModel-DictionaryEntry](
    [AggregateId] [nvarchar](52) NOT NULL,
    [Version] [int] NOT NULL,
    [EntryType] [int] NOT NULL,
    [EntryValue] [nvarchar](max) NULL,
    [EntryRegExp] [nvarchar](max) NULL,
    [CustomId] [nvarchar](max) NULL,
    [CorrelationId] [uniqueidentifier] NOT NULL,
    [TimeStamp] [timestamp] NULL,

csproj

<ItemGroup>
<PackageReference Include="EventFlow.DependencyInjection" Version="0.83.4713"/>
<PackageReference Include="EventFlow.AspNetCore" Version="0.83.4713"/>
<PackageReference Include="EventFlow.MsSql" Version="0.83.4713"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2"/>
</ItemGroup>
.net-core event-sourcing event-flow
1个回答
0
投票

您正在使用

System.Data.SqlClient, Version=4.2.0.0
,请将您的软件包更新到最新版本的
System.Data.SqlClient 4.8.6
- 如果问题没有按照 GitHub 上的此问题的建议得到解决(顺便说一句,我认为他们没有解决它,我也没有解决)他们在 System.Data.SqlClient 中计划的事情)。

下一个解决方案是卸载

System.Data.SqlClient
并使用
Microsoft.Data.SqlClient 5.1.5
- 对于这个 GitHub 提出的问题,他们将在 5.2.0 版本中修复它,该版本应该在本月底发布。

© www.soinside.com 2019 - 2024. All rights reserved.