我正在开发ASP.NET核心应用程序,我在其中实现了将从appsetting.json
读取值的功能为此,我正在学习本教程 - http://benjii.me/2016/04/new-configuration-appsettings-mvc6-web-config-gone/
在本教程中,我遵循以下方式自动绑定所有应用程序设置 -
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
}
在这一特定行 - services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
上,我得到的是异常 -
类型&#39; System.TypeLoadException&#39;的例外情况发生在 Microsoft.Extensions.OptionsModel.dll但未在用户代码中处理
其他信息:无法加载类型 &#39; Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions&#39; 来自assembly&#39; Microsoft.Extensions.DependencyInjection.Abstractions, Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60&#39;。
Project.json
{
"dependencies": {
"Microsoft.AspNetCore.Diagnostics":"1.0.0",
"Microsoft.AspNetCore.Identity": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
"Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": {
"version": "1.0.0",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"net461": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config",
"Views",
"Areas/**/Views",
"appsettings.json"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
我无法弄清楚我在这里缺少什么。有人可以指出我在这里失踪吗?
我的环境是VS2015 Professional update3和Windows 7计算机。
谢谢&amp;此致
维沙尔
答案 0 :(得分:0)
在project.json
中添加以下包"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
此包包含具有扩展方法IServiceCollection Configure<TOptions>