本文轉自:http://www.cnblogs.com/TomGui/p/6438686.html
An error occurred while starting the application.
.NET Core X64 v4.1.1.0 | Microsoft.AspNetCore.Hosting version 1.1.0-rtm-22752 | Microsoft Windows 6.3.9600
報這個錯,一臉懵逼,環境都按官方文檔配置正確了,怎么辦?
1.修改web.config文件,stdoutLogEnabled改為true,如下:
<aspNetCore processPath="dotnet" arguments=".\Dialysis.WebApi.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
補充一點,這個文件是在發布之后的文件里,如果沒有單獨配置發布文件。
就在\bin\Debug\netcoreapp1.1 里面,在根目錄下有web.config文件。
注: 不在源文件的根目錄下面。
另外,需要手動建 這個 logs 文件夾,因為iis不會給你自動創建。
我出這個問題的原因也是因為項目在startup的時候沒有讀到 nlog.config這個文件導致的錯誤。
在開發環境中,把這個文件的屬性配置成“復制到輸出目錄:始終復制” 和 “生成操作:內容” 就可以了。
2.再次打開網站,還是報上述錯誤,別急,查看發布根目錄發現多了一個Logs文件夾,打開里面的stdout_xxx.log文件
Application startup exception: System.IO.FileNotFoundException: Could not find file 'G:\FTP\DialysisWebApi\Dialysis.WebApi.xml'. File name: 'G:\FTP\DialysisWebApi\Dialysis.WebApi.xml' at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent) at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlSystemPathResolver.GetEntity(Uri uri, String role, Type typeOfObjectToReturn) at System.Xml.XmlTextReaderImpl.FinishInitUriString() at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver) at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext) at System.Xml.XmlReader.Create(String inputUri) at System.Xml.XPath.XPathDocument..ctor(String uri, XmlSpace space) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.<>c__DisplayClass24_0.<IncludeXmlComments>b__0() at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.CreateSwaggerProvider(IServiceProvider serviceProvider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() Hosting environment: Production Content root path: G:\FTP\DialysisWebApi Now listening on: http://localhost:22365 Application started. Press Ctrl+C to shut down.
發現缺少文件,把文件復制到發布根目錄下就解決了
發布至IIS微軟官方文檔