gpt4 book ai didi

c# - ASP.NET Core 3.1 Web 应用程序在 IIS Express 上运行时抛出错误 500.30,但在使用 dotnet watch run 时不会抛出错误

转载 作者:行者123 更新时间:2023-12-01 21:56:37 25 4
gpt4 key购买 nike

在 IIS Express 上从 Visual Studio 2019 运行我的应用程序时,网页出现错误 500.30,并在输出中显示:

Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.dll

但是,当使用 dotnet watch run 在终端中运行它时,页面运行不会出现错误并正确显示。

我尝试运行调试器,但错误总是在这一行抛出,

CreateHostBuilder(args).Build().Run();

下面我的ConfigureServives方法完成后

// This method gets called by the runtime. Use this method to add services to the container.
public static void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRouting();
}

我还尝试修复 Visual Studio 2019 以及重新安装 .NET 3.1.100 SDK,但没有成功。

任何帮助将不胜感激!

编辑:

我必须发布程序,然后运行 ​​.exe,但这就是我得到的输出

crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
Application startup exception
System.IO.DirectoryNotFoundException: C:\Users\ray.kochenderfer\Documents\public\hub\public\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at QualityHub.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\ray.kochenderfer\repos\quality_hub\Startup.cs:line 49
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Unhandled exception. System.IO.DirectoryNotFoundException: C:\Users\ray.kochenderfer\Documents\public\hub\public\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at QualityHub.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\ray.kochenderfer\repos\quality_hub\Startup.cs:line 49
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at QualityHub.Program.Main(String[] args) in C:\Users\ray.kochenderfer\repos\quality_hub\Program.cs:line 16

最佳答案

我在 IISExpress 上遇到了同样的问题。解决 500.30 错误的唯一方法是在 OutOfProcess 模式下运行应用程序。

  <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

关于c# - ASP.NET Core 3.1 Web 应用程序在 IIS Express 上运行时抛出错误 500.30,但在使用 dotnet watch run 时不会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59361080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com