【问题标题】:Invalid Cast Exception with on .NET Core 3.1 with 3.0.0-beta1.20306.64.NET Core 3.1 和 3.0.0-beta1.20306.64 上的无效转换异常
【发布时间】:2020-09-27 15:59:45
【问题描述】:
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DateTimeOffset'.
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueFromSqlBufferInternal[T](SqlBuffer data, _SqlMetaData metaData)
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueInternal[T](Int32 i)
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValue[T](Int32 i)
   at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at OpenIddict.EntityFrameworkCore.OpenIddictEntityFrameworkCoreTokenStore`5.FindByIdAsync(String identifier, CancellationToken cancellationToken) in /_/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs:line 401
   at OpenIddict.Core.OpenIddictTokenCache`1.<>c__DisplayClass11_0.<<FindByIdAsync>g__ExecuteAsync|0>d.MoveNext() in /_/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs:line 533
--- End of stack trace from previous location where exception was thrown ---
   at OpenIddict.Core.OpenIddictTokenManager`1.FindByIdAsync(String identifier, CancellationToken cancellationToken) in /_/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs:line 409
   at OpenIddict.Core.OpenIddictTokenManager`1.OpenIddict.Abstractions.IOpenIddictTokenManager.FindByIdAsync(String identifier, CancellationToken cancellationToken) in /_/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs:line 1336
   at OpenIddict.Server.OpenIddictServerHandlers.ValidateTokenEntry.HandleAsync(ProcessAuthenticationContext context) in /_/src/OpenIddict.Server/OpenIddictServerHandlers.cs:line 833
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 54
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 52
   at OpenIddict.Server.OpenIddictServerHandlers.Userinfo.ValidateToken.HandleAsync(ValidateUserinfoRequestContext context) in /_/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs:line 434
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 54
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 52
   at OpenIddict.Server.OpenIddictServerHandlers.Userinfo.ValidateUserinfoRequest.HandleAsync(ProcessRequestContext context) in /_/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs:line 166
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 54
   at OpenIddict.Server.OpenIddictServerProvider.DispatchAsync[TContext](TContext context) in /_/src/OpenIddict.Server/OpenIddictServerProvider.cs:line 52
   at OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandler.HandleRequestAsync() in /_/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs:line 65
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

【问题讨论】:

  • 创建表 [dbo].[OIDC_Tokens]( [Id] [nvarchar](450) NOT NULL, [ApplicationId] [nvarchar](450) NULL, [AuthorizationId] [nvarchar](450) NULL,[类型] [nvarchar](max) NULL,[ConcurrencyToken] [nvarchar](max) NULL,[属性] [nvarchar](max) NULL,[主题] [nvarchar](max) NULL,[状态] [ nvarchar](max) NULL, [ReferenceId] [nvarchar](max) NULL, [Payload] [nvarchar](max) NULL, [ExpirationDate] [nvarchar](max) NULL, [CreationDate] [nvarchar](max) NULL , 约束 [PK_OIDC_Tokens] 主键集群

标签: openiddict


【解决方案1】:

[ExpirationDate] [nvarchar](max) NULL, [CreationDate] [nvarchar](max) NULL

您的架构无效:日期不应存储在 NVARCHAR 列中。 考虑改用DATETIMEOFFSET (7)

【讨论】:

    猜你喜欢
    • 2015-08-10
    • 1970-01-01
    • 2020-02-13
    • 2020-12-05
    • 2020-08-17
    • 1970-01-01
    • 2021-10-02
    • 2021-03-06
    • 1970-01-01
    相关资源
    最近更新 更多