简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM