我试图将一个接口注入我的HomeController,我收到此错误:
InvalidOperationException:尝试激活时无法解析类型"Microsoft.Extensions.Configuration.IConfiguration"的服务
我的Startup类如下:
public Startup(IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddEnvironmentVariables()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options
.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddSingleton(provider => Configuration);
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用它不会过去的包管理器控制台Initializing PowerShell Host....
我以前有这个,最终不得不将计算机恢复到之前的日期.我试过了,它什么都没改变.有没有人有任何想法?
更新 事件查看器下的信息说
Windows PowerShell已启动进程上的IPC侦听线程:22300在AppDomain中:DefaultAppDomain.
我正在尝试在服务器上部署asp.net核心应用程序.我已经完成了以下步骤.
首先,这是一个Windows Server 2012 r2环境,它是一个全新的虚拟机.
我得到控制台应用程序打开说现在正在侦听:http:// localhost:5000 10.我从这台机器上的chrome 转到http:// localhost:5000并找不到404.
我在本地机器上执行步骤7 8 9和10,这是Windows 10我的应用程序.
project.json
{
"dependencies": {
"AutoMapper": "5.1.1",
"EntityFramework": "6.1.3",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},
"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"
},
"frameworks": …Run Code Online (Sandbox Code Playgroud) 可以说我有一个Listbox
<ListBox ItemsSource="{Binding MyList}"/>
Run Code Online (Sandbox Code Playgroud)
我有一个属性:
private List<dynamic> _myList;
public List<dynamic> MyList
{
get { return _myList; }
set
{
if(value==null)return;
_myList = value;
OnPropertyChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
好的,现在我们得到了我的问题:我有几个类,我将有列表,我希望能够在这个ListBox中显示它们.
类别:
public class A
{
public string S { get; set; }
public int I { get; set; }
}
public class B
{
public int C { get; set; }
public string Name { get; set; }
public string F { get; set; }
}
public class C
{
public int I …Run Code Online (Sandbox Code Playgroud) 我正在尝试打补丁/并发布对服务器的调用,但它永远不会到达服务器。我试过用邮递员做这件事,它在那里工作。所以我很确定它与我的代码有关。
基本上,我的帖子和补丁是一样的,所以我只会展示补丁。
protected patch(url: string, body: any): Observable<any> {
let options = this.getRequestOptions(body);
return this.http.patch(this.baseUrl+url,JSON.stringify(body),options);
}
private getRequestOptions(body:any):RequestOptions{
let cpHeaders = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: cpHeaders });
return options;
}
Run Code Online (Sandbox Code Playgroud)
请注意,this.baseUrl = "http://localhost/blah/api/和 url 被传递为test;
我很感激这里的任何帮助。提前致谢
更新
[HttpPut]
public virtual IHttpActionResult Patch([FromBody]T entity)
{
return Ok(_repository.Patch(entity));
}
[HttpPatch]
public virtual IHttpActionResult WebPatch([FromBody]T entity)
{
return this.Patch(entity);
}
Run Code Online (Sandbox Code Playgroud)
我有一个代理配置,如下面的评论所示。
{
"/api": {
"target": "http://localhost/QuickQuoteApi",
"secure": false,
"pathRewrite": {
"^/api": "" …Run Code Online (Sandbox Code Playgroud) 我有一个我正在构建的ASP.NET MVC应用程序,我无法弄清楚为什么被回发的模型总是为空.
CSHTML:
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.HiddenFor(model => model.TotalItemCategoryId, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Label, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Label, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Label, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Value, htmlAttributes: new { @class …Run Code Online (Sandbox Code Playgroud) c# ×3
asp.net-core ×2
asp.net-mvc ×2
.net ×1
angular ×1
deployment ×1
http ×1
iis ×1
powershell ×1
typescript ×1
wpf ×1