- Exception message and full stack trace:
- System.InvalidCastException: Unable to cast object of type 'Volo.Abp.LowCode.EntityFrameworkCore.JsonPaths.WordJsonPathElementSqlGenerationHelper' to type 'Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper'.
at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable1 asyncEnumerable, CancellationToken cancellationToken) at Volo.Abp.Identity.EntityFrameworkCore.EfCoreIdentityUserRepository.FindByNormalizedUserNameAsync(String normalizedUserName, Boolean includeDetails, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlQuerySqlGenerator..ctor(QuerySqlGeneratorDependencies dependencies, IRelationalTypeMappingSource typeMappingSource, Boolean reverseNullOrderingEnabled, Version postgresVersion) at Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlQuerySqlGeneratorFactory.Create() at Microsoft.EntityFrameworkCore.Query.Internal.RelationalCommandCache.GetRelationalCommandTemplate(Dictionary2 parameters)
at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken) at Volo.Abp.Identity.IdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable1 tenantId, String adminUserName)
at Volo.Abp.Identity.UserSharing.UserSharingIdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable`1 tenantId, String adminUserName)
- Steps to reproduce the issue:
- Create an ABP solution using ABP Studio.
- Configure PostgreSQL as the database provider.
- Add or enable the ABP Low-Code module.
- . Initialize the database and execute the Identity data seeding process.
- The exception occurs when IdentityDataSeeder calls FindByNormalizedUserNameAsync.
4 Answer(s)
-
0
Hi,
In 11.0.0 the Low-Code module wraps the EF Core
ISqlGenerationHelperfor every DbContext that implementsIDbContextWithDynamicEntities. The PostgreSQL provider casts this helper to its ownNpgsqlSqlGenerationHelperwhen it builds a query, so every query on your main DbContext fails, not only the data seeding.You can use this workaround for now. Add this class to your EntityFrameworkCore project:
using Microsoft.EntityFrameworkCore.Storage; using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal; using Volo.Abp.LowCode.EntityFrameworkCore.JsonPaths; #pragma warning disable EF1001 public class LowCodeNpgsqlSqlGenerationHelper : NpgsqlSqlGenerationHelper { public LowCodeNpgsqlSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) : base(dependencies) { } public override string DelimitJsonPathElement(string pathElement) { return WordJsonPathElementSqlGenerationHelper.IsWord(pathElement) ? pathElement : base.DelimitJsonPathElement(pathElement); } }Then add this to the
ConfigureServicesmethod of your*EntityFrameworkCoreModule:Configure<AbpDbContextOptions>(options => { options.ConfigureDefaultOnConfiguring((dbContext, optionsBuilder) => { if (dbContext is IDbContextWithDynamicEntities) { optionsBuilder.ReplaceService<ISqlGenerationHelper, LowCodeNpgsqlSqlGenerationHelper>(); } }); });We'll fix this in the next patch release. You can remove the workaround after upgrading. Your ticket has been refunded.
Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Thanks for the explanation and workaround. I can try this workaround. Just to confirm, is this a known bug in ABP 11.0.0? Is there a plan to fix it in a future release? If so, could you let us know which version is expected to include the fix?
Thanks again for your help!
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi,
Yes. The fix is already merged and will be included in 11.0.1. I don't have an exact release date yet, so please use the workaround until then.
Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Thanks for the update!
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)