ara*_*333 7 c# iis asp.net-core-webapi
我有一个使用Web Core API的MVC网站.在进行了微小的更改和部署之后,我意外地收到了错误; 响应状态代码不表示成功:500(内部服务器错误).所以我启用了Web Core API的日志文件(请参阅https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.0#aspnet-core -module-stdout-log)我收到此错误消息;
应用程序启动异常:System.Collections.Generic.KeyNotFoundException:给定的键不存在于字典中.Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String依赖项)中的Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String依赖项)中的System.Collections.Generic.Dictionary2.get_Item(TKey键)在Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(字符串依赖)在Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.d__4.MoveNext()在System.Linq.Enumerable.d__172.MoveNext()在系统.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()at Microsoft.Extensions.DependencyInject.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)at Properties.API.Startup.ConfigureServices(IServiceCollection) SER 恶意)---抛出异常的前一个位置的堆栈跟踪结束---在Microsoft.AspNetCore的Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection服务)的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处. Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()中的Hosting.Internal.WebHost.EnsureApplicationServices()主机环境:暂存内容根路径:C:\ inetpub\wwwroot\SIR现在正在侦听:http:// localhost:33007申请开始了.按Ctrl + C关闭.
更新:它倒下的线是;
services.AddMvcCore()AddJsonFormatters();
在ConfigureServices中.
我如何调试它以找出导致这种情况的原因?
public class Startup {
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($ "appSettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
.
.
.
Run Code Online (Sandbox Code Playgroud)public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvcCore().AddJsonFormatters(); services.Configure<IISOptions>(options => new IISOptions { AutomaticAuthentication = true, ForwardClientCertificate = false, ForwardWindowsAuthentication = false });
var connectionStringMSurveyV2 = Configuration.GetConnectionString("MSurveyV2Db");
services.AddScoped<MSurveyV2Db>(_ => new MSurveyV2Db(connectionStringMSurveyV2));
var connectionStringSir = Configuration.GetConnectionString("SirDb");
services.AddScoped<SirDb>(_ => new SirDb(connectionStringSir));
services.AddScoped<IPropertiesRepo, PropertiesRepo>();
services.AddScoped<ISirUoW, SirUoW>();
services.AddScoped<IPropertyUoW, PropertyUoW>();
services.AddScoped<Services.IMailService, Services.MailService>();
}
Run Code Online (Sandbox Code Playgroud)
...
您没有说明您正在使用哪个版本的 ASP.NET Core。如果是2.0+,可以配置NLogProgram.cs在启动前加载:
public static class Program
{
public static void Main(string[] args)
{
var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
BuildWebHost(args, config).Run();
}
catch (System.Exception ex)
{
logger.Error(ex, "An error occurred during program startup");
throw;
}
}
private static IWebHost BuildWebHost(string[] args, IConfigurationRoot config)
{
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.UseNLog()
.Build();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1058 次 |
| 最近记录: |