Search code examples
c#.netpostgresql-10

The type initializer for 'Npgsql.PoolManager' threw an exception


Getting this exception "The type initializer for 'Npgsql.PoolManager' threw an exception." only on window 7.

public string ValidateDefaultInstancePostgreSqlServer()
    {
        string found = "0";

        try
        {
            using (NpgsqlConnection postGresConnection = new NpgsqlConnection())
            {
                postGresConnection.ConnectionString = "Server=localhost;Port=5432;Database=postgres;User Id=postgres;Password=postgre123;Pooling=true;MinPoolSize=1;MaxPoolSize=100;Command Timeout=600;Timeout=600;";
                using (NpgsqlCommand checkDBCommand = postGresConnection.CreateCommand())
                {
                    postGresConnection.Open();

                    found = "1";
                }
            }
        }
        catch (Exception e)
        {}

Note : the same code works fine on window 10. Running this function from a installsheild setup. Please help.


Solution

  • I resolved my issue by updating System.ValueTuple.dll with the latest version. The issue came out to be the incompatibility between the Npgsql.dll and System.ValueTuple.dll.

    I think, if we have added references from nuget, the issue would not have came in first place. but strange it came only on window 7 or 32 bit machine.