9
votes

Say I put the settings below in appsettings.json.

"MySettings": {
    "SmtpHost": "smtp.mydomain.com"",
    "WebService": "http://localhost:1337"
}

And I have the class below to hold those settings.

public class MySettings
{
    public string SmtpHost{ get; set; }
    public string WebService{ get; set; }
}

With RC1 I would use the line of code below in the ConfigureServices() method to load those configuration settings.

services.Configure<MySettings>(Configuration.GetSection("MySettings"));

But in RC2 that same line of code gives me this error

Cannot convert from 'MicrosoftExtensions.Configuration.IConfigurationSection' to 'System.Action<MySettings>'.

2

2 Answers

11
votes

You simply need to reference a different package with RC2. In your project.json simply add a reference to the "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final" package, and you'll get the correct extension method that you're looking for.

"dependencies": {
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final"
}

Like several of the changes with ASP.NET Core RC2, there was a lot of re-packing and moving of things. I put together a migration guide that you might find useful.

3
votes

you need to add the package:

"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final",

and make sure you have this using:

using Microsoft.Extensions.Configuration;