How to fix UsePostgreSqlStorage is obsolete: 'Will be removed in 2.0. in Hangfire string connection?

The following code snippet is currently generating a warning:

builder.Services.AddHangfire(config => config

The warning message is as follows:

‘PostgreSqlBootstrapperConfigurationExtensions.UsePostgreSqlStorage(IGlobalConfiguration, string)’ is marked as obsolete: ‘This method will be removed in version 2.0. Please use the UsePostgreSqlStorage(Action) overload instead.’

The versions of the packages currently in use are:

<PackageReference Include="Hangfire.AspNetCore" Version="1.8.12" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.20.8" />

Despite the warning, this is the only configuration that works for me. Any assistance would be greatly appreciated.

This isn’t quite an answer but have you looked around the connections factories in their code

[Obsolete("Will be removed in 2.0, please use the overload with IConnectionFactory argument")]
public PostgreSqlStorage(string connectionString) : this(connectionString, new PostgreSqlStorageOptions()) { }


I’ve tried to set up Hangfire with the corrected configuration. Still gives me an error:

builder.Services.AddHangfire(config => config
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180) .UseSimpleAssemblyNameTypeSerializer() 
.UsePostgreSqlStorage(options => 
    options.ConnectionString = connString; 


‘PostgreSqlBootstrapperOptions’ does not contain a definition for ‘ConnectionString’ and no accessible extension method ‘ConnectionString’ accepting a first argument of type ‘PostgreSqlBootstrapperOptions’ could be found (are you missing a using directive or an assembly reference?)

I got it working without a warning.

It appears that the UseNpgsqlConnection method is a valid method within the PostgreSqlStorageOptions class in my version of Hangfire. This method is likely a convenience method provided by the Hangfire.PostgreSql extension to simplify the configuration of the PostgreSQL storage.

builder.Services.AddHangfire(config => config
    .UsePostgreSqlStorage(options => options.UseNpgsqlConnection(connString)));