在IIS Express上运行时,ASP.NET Core 3.1 Web应用程序引发错误500.30,而在使用dotnet watch run时则不会引发错误500.30 [英] ASP.NET Core 3.1 web application throws error 500.30 when run on IIS Express, but not when using dotnet watch run

查看:81
本文介绍了在IIS Express上运行时,ASP.NET Core 3.1 Web应用程序引发错误500.30,而在使用dotnet watch run时则不会引发错误500.30的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When running my application from Visual Studio 2019 on IIS Express the web page gives error 500.30 and in the output it says,

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

但是,在使用 dotnet watch run 在终端中运行它时,该页面运行无错误,并且显示正确.

However, when running it in a terminal using dotnet watch run the page runs without errors and displays correctly.

我尝试运行调试器,并且错误总是在此行引发,

I've tried running the debugger and the error is always thrown on this line,

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

以下我的ConfigureSerives方法完成后

after my ConfigureSerives Method below completes

// 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,但是没有运气.

I've also tried repairing my Visual Studio 2019 as well as reinstalling .NET 3.1.100 SDK with no luck.

任何帮助将不胜感激!

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

I had to publish the program and then run the .exe, but this was the output I got

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

推荐答案

存在 github问题关于此问题.

使用2.x版本的Microsoft.Extensions.*和ASP.NET Core 3.0/3.1项目中的Microsoft.AspNetCore.*软件包是*不支持.

Using 2.x versions of Microsoft.Extensions.* and Microsoft.AspNetCore.* packages in an ASP.NET Core 3.0/3.1 project is *not supported.

在我的情况下,我依赖于nuget包,而依赖于Microsoft.AspNetCore2.x.x.删除Nuget后,该项目在IIS Express下运行没有问题.

In my case i was depending on nuget package which was depending on Microsoft.AspNetCore 2.x.x. After removing the nuget the project ran without issues under IIS Express.

如果任何人仍然遇到此问题,则可以尝试使用2.x版删除依赖项,因为它们会从SDK中自动解决.

If anyone is still having this issue, you can try to remove dependencies with version 2.x because they are automatically resolved from the SDK.

这篇关于在IIS Express上运行时,ASP.NET Core 3.1 Web应用程序引发错误500.30,而在使用dotnet watch run时则不会引发错误500.30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆