IzyPro/WatchDog

Npgsql throws: invalid byte sequence for encoding "UTF8": 0x00

Closed this issue · 1 comments

Description
Npgsql throws an exception because the post request contains binary data.
The data saves to my Postgres database, but because of the exception, I do not get response data.

Steps to reproduce:
Request Model:

public sealed class Dto
{
    [Required]
    public string Name { get; set; }

    [DefaultValue(false)]
    public bool IsActive { get; set; }

    public IFormFile ImageUpload { get; set; }
}

Error:

warn: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[2]
      The response has already started, the error page middleware will not be executed.
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      Npgsql.PostgresException (0x80004005): 22021: invalid byte sequence for encoding "UTF8": 0x00
         at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|211_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
         at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
         at Dapper.SqlMapper.ExecuteImplAsync(IDbConnection cnn, CommandDefinition command, Object param) in /_/Dapper/SqlMapper.Async.cs:line 646
         at WatchDog.src.Helpers.ExternalDbHelper.InsertWatchExceptionLog(WatchExceptionLog log)
         at WatchDog.src.Managers.DynamicDBManager.InsertWatchExceptionLog(WatchExceptionLog log)
         at WatchDog.src.WatchDogExceptionLogger.LogException(Exception ex, RequestModel requestModel)
         at WatchDog.src.WatchDogExceptionLogger.InvokeAsync(HttpContext context)
         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.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
        Exception data:
          Severity: ERROR
          SqlState: 22021
          MessageText: invalid byte sequence for encoding "UTF8": 0x00
          Where: unnamed portal parameter $8
          File: mbutils.c
          Line: 1665
          Routine: report_invalid_encoding

Details:

  • Project Type: ASP.NET API
  • Framework Version: .NET 6
  • WatchDog Version: 1.3.1
  • Database: Postgres

Hi @coderBane
A pre-release version (v1.3.3-rc) that fixes this issue has been published