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>
'.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With