9

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>'.

Clint B
  • 4,610
  • 2
  • 18
  • 22

2 Answers2

11

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.

David Pine
  • 23,787
  • 10
  • 79
  • 107
  • 1
    LOL. I posted the question with the intent of answering it myself because I couldn't find an answer to it on SO. So other people who might run into the same problem can get a quick answer. You beat me to it. Nice job! – Clint B May 25 '16 at 13:17
  • @ClintB, I pointed this out to the community on the .NET slack room. There was a lot of initial confusion about it. I'm happy I could help. – David Pine May 25 '16 at 13:19
  • Thanks for the link! I bookmarked it and will read over it. I was trying to decide who to give the accepted answer to between you and Joe. Your migration guide makes you the winner. – Clint B May 25 '16 at 13:20
  • 1
    @ClintB, thanks. BTW - he is in the same slack room, so he probably got the answer from me originally :P – David Pine May 25 '16 at 13:22
3

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;
Joe Audette
  • 35,330
  • 11
  • 106
  • 99
  • LOL. I posted the question with the intent of answering it myself because I couldn't find an answer to it on SO. So other people who might run into the same problem can get a quick answer. You beat me to it. Nice job! – Clint B May 25 '16 at 13:18