15

I have this line

string sConnectionString = ConfigurationManager.ConnectionStrings["Hangfire"].ConnectionString;

And it requires to include System.Configuration

In which place of the project I have to add reference to System.Configuration because I cannot find a classic place to do it under References?

enter image description here

2
  • .Net Core projects use a different configuration model that is based on Microsoft.Extensions.Configuration rather than System.Configuration. Where is your actual HangFire connection-string is set? In your appsettings.json? Commented Nov 23, 2016 at 12:57
  • @haim770 I am study this manual talkingdotnet.com/integrate-hangfire-with-asp-net-core-web-api Commented Nov 23, 2016 at 12:57

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I agree with you but why the manual I am facing has presented the old approach that is not supported now in Asp.Net Core ? Does it mean that manual is incorrect?
There's nothing "incorrect" about it, per se. You can build Asp.Net Core apps that are targeting the full framework (4.6). But you won't gain all the benefits and portability of the Core framework.
-2

@Dimi Right Click on References folder -> Add References -> Search configuration -> check on System.Configuration -> Click on ok.

then add Namespaces on your .cs file i.e

using System.Configuration;

enter image description here enter image description here

7 Comments

It says NO ITEMS FOUND
Sorry I cannot see the same windows like you. I have created ASP.NET Core Webapi project. See my updated question, please
visit above links
@Dimi: This is ASP.NET Core/.NET Core it is completely modular and based on NuGet packages. You won't have the files lying around as with .NET Framework before. Whatever you need, you need to reference it in project.json (soon inside csproj when VS2017 comes)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.