ASP.NET Core 项目使用 Swagger,应用程序无法访问文档 xml 文件。在其他主机上一切正常。一切都在本地机器上运行。错误文字:
FileNotFoundException: Could not find file 'D:\home\site\wwwroot\Web.xml'.
重量跟踪错误:
System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access,
FileShare share, int bufferSize, FileOptions options)
System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access,
FileShare share, int bufferSize)
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials,
IWebProxy proxy, RequestCachePolicy cachePolicy)
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
System.Xml.XmlTextReaderImpl.OpenUrl()
System.Xml.XmlTextReaderImpl.Read()
System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
System.Xml.XPath.XPathDocument..ctor(string uri, XmlSpace space)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions+<>c__DisplayClass25_0.<IncludeXmlComments>b__0()
Swashbuckle .AspNetCore.SwaggerGen.SwaggerGenOptions
.CreateSwaggerProvider(IServiceProvider serviceProvider)
Microsoft.Extensions.DependencyInjection
.SwaggerGenServiceCollectionExtensions.CreateSwaggerProvider(IServiceProvider serviceProvider)
Microsoft.Extensions.DependencyInjection.ServiceLookup
.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceLookup
.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup
.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceLookup
.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceProvider+<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
Microsoft.Extensions.Internal.ActivatorUtilities+ConstructorMatcher
.CreateInstance(IServiceProvider provider)
Microsoft.Extensions.Internal.ActivatorUtilities
.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next)
Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
导致错误的代码:
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, "Web.xml");
c.IncludeXmlComments(xmlPath);

PlatformServices已弃用。您不再需要在新项目中使用它。您可以根据 github 链接使用它的替换。
尝试替换为
更新
如果它不起作用,请尝试此选项