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?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. DSpada 0 Reputation points
    2024-10-04T06:27:30.3666667+00:00

    Hi @Anonymous , I run dotnet --info on both server and the versione are the same:

    server 1:

    qua_server

    server 2:

    pro_server

    we also tried to uninstall and reinstall .Net Hosting Bundle, also tried to upgrade .Net Hosting bundle to 8, but in Server 2 nothing change.

    We also tried to build project OutOfProcess but still nothing.

    We think that could be something in "security policy" of IIS but we can't find what can block the library, since running the API with kestrel the library works.


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.