Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The code snippet provided below is currently generating a warning:

builder.Services.AddHangfire(config => config
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UsePostgreSqlStorage(defaultConnString));

The warning message is as follows:

'PostgreSqlBootstrapperConfigurationExtensions.UsePostgreSqlStorage(IGlobalConfiguration, string)' is obsolete: 'Will be removed in 2.0. Please use UsePostgreSqlStorage(Action) overload.'

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.

like image 837
Sergey M. Avatar asked Jan 01 '26 06:01

Sergey M.


1 Answers

Thanks to stuartd point in a right direction.

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.

Working code without a warning:

builder.Services.AddHangfire(config => config
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UsePostgreSqlStorage(options => options.UseNpgsqlConnection(connString)));
like image 159
Sergey M. Avatar answered Jan 02 '26 21:01

Sergey M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!