The tutorial your're following is probably using Asp.Net Core targeting the full .Net Framework (4.6) that is capable of relying on System.Configuration
(that is not portable and not supported in CoreFX).
.Net Core projects (being cross-platform) use a different configuration model that is based on Microsoft.Extensions.Configuration
rather than on System.Configuration
.
Assuming your Hangfire
connection-string is defined in your appsettings.json
:
{
"ConnectionStrings": {
"HangFire": "yourConnectionStringHere"
}
}
You can read it in your Startup.cs
:
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
this.Configuration = builder.Build();
var hangFireCS = this.Configuration.GetConnectionString("HangFire");
}
}
Also, you're gonna need the Microsoft.Extensions.Configuration.Json
package to use the AddJsonFile()
extension method.
Microsoft.Extensions.Configuration
rather thanSystem.Configuration
. Where is your actualHangFire
connection-string is set? In yourappsettings.json
? – Teodor