Starts in:
2 DAYS
9 HRS
51 MIN
22 SEC
Starts in:
2 D
9 H
51 M
22 S
Open Closed

PostgreSQL and Postgis not working after migration #5002


User avatar
0
Leonardo.Willrich created

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v7.2.1
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

It can be a long shot, but, I think it is worth a try asking here as it could be experienced by another user as well. I have migrated an application Blazor WASM from 5.3 to 7.2.1. After the migration, when I'm trying to query a table with a 'geometry' field type, it is returning an exception as below:

[14:31:38 ERR] Can't cast database type .<unknown> to Geometry System.InvalidCastException: Can't cast database type .<unknown> to Geometry at Npgsql.Internal.TypeHandling.NpgsqlTypeHandler.ReadCustom[TAny](NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription) at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal) at lambda_method5475(Closure, DbDataReader, Int32[]) at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadObject(DbDataReader reader, Int32 ordinal, ReaderColumn column) at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadRow() at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.InitializeAsync(DbDataReader reader, IReadOnlyList1 columns, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList1 columns, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList1 columns, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at TVD_Holdings_Ltd.SBC.SBC.UnitsMap.UnitsMapAppService.GetTestRecordsFromTestPostgis() in D:\Source\SmartBridge\SbcWeb530\src\TVD_Holdings_Ltd.SBC.Application\SBC\UnitsMap\UnitsMapAppService.cs:line 89 at lambda_method5469(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 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.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

I created a new table and EF first code is creating the table correctly. But, adding a record on this I'm getting this exception:

[14:05:31 ERR] An exception occurred in the database while saving changes for context type 'TVD_Holdings_Ltd.SBC.EntityFrameworkCore.SBCDbContext'. Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> Npgsql.NpgsqlException (0x80004005): The NpgsqlDbType 'Geometry' isn't present in your database. You may need to install an extension or upgrade to a newer version.

Do you have any idea what could be wrong? If I return to the previous version, 5.3 and .NET 6, it works with no issues.


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a simple ef core project to test.

    It seems related to https://github.com/npgsql/npgsql/

  • User Avatar
    0
    Leonardo.Willrich created

    HI Maliming,

    I also think it is related to NpgSQL. I've raised an issue in the Github. What is bugging me is that I've migrated another similar project recently to version 7.1.0 and that worked very well. The projects are very similar, especially EntityFramework and Domain projects.

    I'll create a simple project and see how it goes.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    👍

  • User Avatar
    0
    Leonardo.Willrich created

    It works in a simple project. I'm checking the Nuget package versions, but, it seems to be Ok. I've updated the other project to version 7.2.1 and it is still working. It is just in one project that I'm getting those weird issues. It seems that the UseNetTopologySuite() is not working and it is not mapping the types correctly.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you test the UseNetTopologySuite in a new template project.

    and share it with me. liming.ma@volosoft.com

  • User Avatar
    0
    Leonardo.Willrich created

    I found the issue, finally. The project has an implementation to write the logs in the database, it is an ILogEventSink implementation for Serilog. It creates a connection, a dbcommand, and using an insert statement it just adds to the database. For some reason, when opening the connection, it is messing with the database and DbContext.

    Do you have an example of how to write logs into the database by implementing an ILogEventSink or any other way?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Do you have an example of how to write logs into the database by implementing an ILogEventSink or any other way?

    hi

    I don't have experience with this.

  • User Avatar
    0
    Leonardo.Willrich created

    I've fixed it by postponing the NpgSql.Connection call after Host.ApplicationInitialization.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06