NPGSQL - Common Language Runtime detected an invalid program.

DSpada 0 Reputation points
2024-10-01T06:22:10.66+00:00

I have two servers with windows server 2019 and an a Simple API project developed with .NET 8. The project use Npgsql library at version 4.0.0.
The configuration between servers are the same:

  • same path
  • same .NET hosting bundle
  • same IIS configuration
  • same build

The API opens connection, get postgreSQL Database version and closes the connection.

But on the first server the API works correctly on the second one it return this error:

Values Problem to open the connection
      System.InvalidProgramException: Common Language Runtime detected an invalid program.
         at Npgsql.NpgsqlDataReader.Read(Boolean async)
         at Npgsql.NpgsqlDataReader.Read()
         at Npgsql.PostgresDatabaseInfo.LoadBackendTypes(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async)
         at Npgsql.PostgresDatabaseInfo.LoadPostgresInfo(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async)
         at Npgsql.PostgresDatabaseInfoFactory.Load(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async)
         at Npgsql.NpgsqlDatabaseInfo.Load(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async)
         at Npgsql.NpgsqlConnector.LoadDatabaseInfo(NpgsqlTimeout timeout, Boolean async)
         at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
         at Npgsql.ConnectorPool.AllocateLong(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Npgsql.NpgsqlConnection.Open()
         at MyAPI.Values.Values(String httpRequestDomainName) in C:\MyAPI\Controllers\Values.cs:line 45

I check permission, web.config, IIS configuration, folder permission, CLR configuration and between server are the same

I tried everything, reset IIS, clear cache, reboot servers but without success.

can you give me support?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,834 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,551 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,902 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.