温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Not able to host .Net Core 3.1 Web API on IIS

其他 - 无法在IIS上托管.Net Core 3.1 Web API

发布于 2020-03-29 22:01:15

我将.net core 2.2 Web api升级到了.net core 3.1。现在,我可以使用控制台从控制台运行它dotnet myapi.dll,但是当我尝试将其托管在ISS上时,出现以下异常。

我已经安装了,AspNetCore Module V2并且此模块引发异常,我无法理解缺少的部分。

Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:Microsoft.Extensions.Hosting.IHostedService[] -> Microsoft.AspNetCore.Hosting.GenericWebHostService -> Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.AspNetCore.Server.IIS.Core.IISNativeApplication, Microsoft.Extensions.Hosting.IHostApplicationLifetime, Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider, Microsoft.Extensions.Options.IOptions``1[Microsoft.AspNetCore.Builder.IISServerOptions], Microsoft.Extensions.Logging.ILogger

以下是我的 Program.cs

Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(webHostBuilder =>
                {
                    webHostBuilder
                        .UseStartup<Startup>();
                })
                .Build()
                .Run();

以下是我的 Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }


    public ILifetimeScope AutofacContainer { get; private set; }

    public void ConfigureContainer(ContainerBuilder builder)
    {
        // Register your own things directly with Autofac, like:
        ...couple of my Ioc registrations
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddNLog();
        services.Configure<IISServerOptions>(options =>
        {
            options.AutomaticAuthentication = false;
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();

        app.UseEndpoints(endpoints => {
            endpoints.MapControllers();
        });
    }

致电AddNLog()是我们的客户实施,以覆盖.net核心提供的记录器。

我用paket代替,nuget所以下面是我的paket.dependencies文件。

references: strict
source https://api.nuget.org/v3/index.json
framework: auto-detect

nuget Autofac 5.0.0
nuget Autofac.Extensions.DependencyInjection 6.0.0
nuget Autofac.Extras.DynamicProxy 4.5.0
nuget AutoFixture 4.5.0
nuget AutoFixture.AutoMoq 4.5.0
nuget AutoFixture.Xunit2 4.5.0
nuget AutoMapper >= 8.0.0
nuget AutoMapper.Extensions.Microsoft.DependencyInjection
nuget bootstrap 3.3.7 prerelease
nuget Castle.Core 4.3.1 prerelease
nuget Common.Logging 3.4.1
nuget Common.Logging.Core 3.4.1
nuget DnsClient 1.2
clitool dotnet-xunit 2.3.1
nuget Fare 2.1.1
nuget FileHelpers 3.3.0
nuget FluentAssertions 5.4.1
nuget Flurl 2.8.2
nuget JetBrains.Annotations 2019.1.3
nuget Microsoft.AspNet.Cors 5.2.7
nuget Microsoft.AspNet.WebApi 5.2.7
nuget Microsoft.AspNet.WebApi.Client 5.2.7
nuget Microsoft.AspNet.WebApi.Core 5.2.7
nuget Microsoft.AspNet.WebApi.Cors 5.2.7
nuget Microsoft.AspNet.WebApi.WebHost 5.2.7
nuget Microsoft.Azure.AppService.ApiApps.Service 0.9.64
nuget Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.0
nuget Microsoft.DotNet.PlatformAbstractions >= 3.1.1
nuget Microsoft.Extensions.Caching.Abstractions >= 3.1.1
nuget Microsoft.Extensions.Caching.Memory >= 3.1.1
nuget Microsoft.Extensions.Configuration >= 3.1.1
nuget Microsoft.Extensions.Configuration.Abstractions >= 3.1.1
nuget Microsoft.Extensions.Configuration.Binder >= 3.1.1
nuget Microsoft.Extensions.Configuration.EnvironmentVariables >= 3.1.1
nuget Microsoft.Extensions.Configuration.FileExtensions >= 3.1.1
nuget Microsoft.Extensions.Configuration.Json >= 3.1.1
nuget Microsoft.Extensions.DependencyInjection >= 3.1.1
nuget Microsoft.Extensions.DependencyInjection.Abstractions >= 3.1.1
nuget Microsoft.Extensions.DependencyModel >= 3.1.1
nuget Microsoft.Extensions.FileProviders.Abstractions >= 3.1.1
nuget Microsoft.Extensions.FileProviders.Physical >= 3.1.1
nuget Microsoft.Extensions.FileSystemGlobbing >= 3.1.1
nuget Microsoft.Extensions.Logging >= 3.1.1
nuget Microsoft.Extensions.Logging.Abstractions >= 3.1.1
nuget Microsoft.Extensions.Logging.Configuration >= 3.1.1
nuget Microsoft.Extensions.Logging.Console >= 3.1.1
nuget Microsoft.Extensions.Logging.Debug >= 3.1.1
nuget Microsoft.Extensions.Options >= 3.1.1
nuget Microsoft.Extensions.Primitives >= 3.1.1
nuget Microsoft.NET.Test.Sdk 16.5.0
nuget Microsoft.NETCore.DotNetAppHost 3.1.1
nuget Microsoft.NETCore.DotNetHostPolicy 3.1.1
nuget Microsoft.NETCore.Platforms 3.1
nuget Microsoft.Web.Infrastructure 1.0.0
nuget Microsoft.Win32.Primitives 4.3.0
nuget MongoDB.Bson 2.10.1
nuget MongoDB.Bson.signed 2.10.1
nuget MongoDB.Driver 2.10.1
nuget MongoDB.Driver.Core 2.10.1
nuget Moq 4.10.1
nuget Moq.AutoMock 1.1.0.96
nuget MSBuild.Microsoft.VisualStudio.Web.targets 14.0.0.3
nuget NETStandard.Library 2.0.3
nuget Newtonsoft.Json 12.0.3
nuget NLog 4.6.8
nuget NodaTime 3.0.0-beta01
nuget NodaTime.Testing 3.0.0-beta01
nuget Polly 7.2.0
nuget protobuf-portable-net 2.0.0.668
nuget Purplelight.Framework.Autofac.Integration.WebApi 0.2.2
nuget Remotion.Linq 2.2.0
nuget RestSharp 106.10.1

nuget ShellProgressBar >= 4.2.0
nuget SqlBulkTools.NetStandard 2.1.18
nuget SSH.NET 2016.0.0
nuget StackExchange.Redis 2.0.519
nuget StackExchange.Redis.Extensions.Jil 4.0.5
nuget Swashbuckle 5.6.0
nuget Swashbuckle.Core 5.6.0
nuget System.AppContext 4.3.0
nuget System.Buffers 4.5.0
nuget System.Collections 4.3.0
nuget System.Collections.Concurrent 4.3.0
nuget System.Collections.Immutable 1.7.0
nuget System.ComponentModel 4.3.0
nuget System.ComponentModel.Annotations 4.7.0
nuget System.Configuration.ConfigurationManager 4.7.0
nuget System.Console 4.3.1
nuget System.Diagnostics.Debug 4.3.0
nuget System.Diagnostics.DiagnosticSource 4.7.0
nuget System.Diagnostics.Tools 4.3.0
nuget System.Diagnostics.Tracing 4.3.0
nuget System.Globalization 4.3.0
nuget System.Globalization.Calendars 4.3.0
nuget System.Interactive.Async 3.2.0
nuget System.IO 4.3.0 prerelease
nuget System.IO.Compression 4.3.0
nuget System.IO.Compression.ZipFile 4.3.0
nuget System.IO.FileSystem 4.3.0
nuget System.IO.FileSystem.Primitives 4.3.0
nuget System.Linq 4.3.0
nuget System.Linq.Expressions 4.3.0
nuget System.Memory >= 4.5.2
nuget System.Net.Primitives 4.3.0
nuget System.Net.Sockets 4.3.0
nuget System.ObjectModel 4.3.0
nuget System.Reflection 4.3.0
nuget System.Reflection.Extensions 4.3.0
nuget System.Reflection.Primitives 4.3.0
nuget System.Resources.ResourceManager 4.3.0
nuget System.Runtime 4.3.0 prerelease
nuget System.Runtime.Caching 4.5.0
nuget System.Runtime.CompilerServices.Unsafe >= 4.5.1
nuget System.Runtime.Extensions 4.3.0
nuget System.Runtime.Handles 4.3.0
nuget System.Runtime.Numerics 4.3.0
nuget System.Security.AccessControl 4.7.0
nuget System.Security.Permissions 4.7.0
nuget System.Security.Principal.Windows 4.7.0
nuget System.ServiceModel.Duplex >= 4.7.0
nuget System.ServiceModel.Http >= 4.7.0
nuget System.ServiceModel.Primitives >= 4.7.0
nuget System.ServiceModel.NetTcp >= 4.7.0
nuget System.ServiceModel.Security >= 4.7.0
nuget System.Text.Encoding >= 4.3.0
nuget System.Text.Encoding.Extensions >= 4.3.0
nuget System.Text.RegularExpressions >= 4.3.0
nuget System.Threading >= 4.3.0
nuget System.Threading.Tasks >= 4.3.0
nuget System.Threading.Timer >= 4.3.0
nuget System.ValueTuple >= 4.5.0
nuget System.Xml.ReaderWriter >= 4.3.0
nuget System.Xml.XDocument >= 4.3.0
nuget WebActivatorEx 2.2.0
nuget WebGrease 1.6.0
nuget xBehave
nuget xunit 2.4.0
nuget xunit.abstractions 2.0.2
nuget xunit.analyzers 0.10.0
nuget xunit.assert 2.4.0
nuget xunit.core 2.4.0
nuget xunit.extensibility.core 2.4.0
nuget xunit.extensibility.execution 2.4.0
nuget xunit.runner.console 2.4.0
nuget xunit.runner.visualstudio 2.4.0
nuget ZeroFormatter 1.6.4
nuget NLog.Web.AspNetCore
nuget NLog.Extensions.Logging
nuget Dapper 2.0.30
nuget Dapper.Contrib 2.0.30
nuget IdentityModel 4.1.1
nuget System.IdentityModel.Tokens.Jwt 5.6.0
nuget Microsoft.IdentityModel.Tokens 5.6.0
nuget Microsoft.IdentityModel.JsonWebTokens 5.6.0
nuget Microsoft.EntityFrameworkCore 3.1.1
nuget Microsoft.EntityFrameworkCore.Analyzers 3.1.1
nuget Microsoft.EntityFrameworkCore.InMemory 3.1.1
nuget Microsoft.EntityFrameworkCore.SqlServer 3.1.1
nuget System.Drawing.Common 4.7.0
nuget NEventStore 7.0.0
nuget NEventStore.Persistence.Sql 7.2.0
nuget NEventStore.Serialization.Json 7.0.0
nuget NEventStore.PollingClient 7.0.0
nuget Microsoft.AspNetCore.Hosting
nuget Microsoft.AspNetCore.Mvc
nuget Microsoft.AspNetCore.Mvc.Core
nuget Microsoft.AspNetCore.Mvc.Formatters.Json
nuget Microsoft.AspNetCore.Diagnostics
nuget Microsoft.AspNetCore.HttpsPolicy
nuget Microsoft.AspNetCore

我探索了一下,没有找到太多帮助。我创建了一个新的asp.net核心Web API,并且看到该模板带有或多或少的类似配置。我在这里想念什么?

查看更多

提问者
Pradeep
被浏览
39
Tratcher 2020-02-11 00:07

删除Microsoft.AspNetCore。* nuget软件包,这些软件包在3.0中不再存在,因此您将安装2.x版本。 https://docs.microsoft.com/zh-cn/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#remove-obsolete-package-references