。Net Core 2.1方法未找到:MediaTypeHeaderValue.Parse(System.String)

问题描述 投票:0回答:1

配置中的net core 2.1存在以下问题:

MissingMethodException:找不到方法:'Microsoft.Net.Http.Headers.MediaTypeHeaderValue Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(System.String)'。

这是startup.cs的代码

公共类启动{公共启动(IConfiguration配置,IHostingEnvironment env){配置=配置;

        //IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
        //                                                .SetBasePath(env.ContentRootPath)
        //                                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

        //Configuration = configurationBuilder.Build();

        var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
        XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

        AutoMapperVmConfig.RegisterMappings();
        AutoMapperDtoConfig.RegisterMappings();
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        //services.AddMvc()
        //    .AddJsonOptions(options =>{
        //            options.SerializerSettings.ContractResolver = new DefaultContractResolver();
        //        }
        //    );

        services
            .AddMvc()
            .AddJsonOptions(options => (options.SerializerSettings.ContractResolver as DefaultContractResolver).IgnoreSerializableAttribute = true);

        services.AddAutoMapper();

        // Adds a default in-memory implementation of IDistributedCache
        services.AddDistributedMemoryCache();
        services.AddSession(options =>
        {
            // Set a short timeout for easy testing.
            options.IdleTimeout = TimeSpan.FromSeconds(10);
            options.Cookie.HttpOnly = true;
        });

        services.Configure<ConnectionStringsMyWallet>(Configuration.GetSection("ConnectionStringsMyWallet"));

        services.AddKendo();

        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        //registrazione dei componenti con Castle Windsor
        var windsorContainer = new WindsorContainer();

        windsorContainer.Register(Component.For<EfDbUpdateException>());

        windsorContainer.Register(
            Component.For<IUserDataRepository>().ImplementedBy<EfUserDataRepository>().LifestyleTransient().Interceptors<EfDbUpdateException>(),
            Component.For<IPeriodoRepository>().ImplementedBy<EfPeriodoRepository>().LifestyleTransient().Interceptors<EfDbUpdateException>(),
            Component.For<IMovimentiRepository>().ImplementedBy<EfMovimentiRepository>().LifestyleTransient().Interceptors<EfDbUpdateException>(),
            Component.For<IUserSessionProvider>().ImplementedBy<UserSessionValuesInHttpContext>().LifestyleTransient()
        );

        IServiceProvider serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(windsorContainer, services);

        return serviceProvider;
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }         

        app.UseSession();
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}
asp.net-core-2.1
1个回答
0
投票

我添加了nuget包Microsoft.Aspnetcore.All,这解决了我的问题。但是包Microsoft.Aspnetcore.All太大了。我从Microsoft.Aspnetcore.All的依赖项中搜索程序包,并找到合适的包-Microsoft.AspNetCore.Mvc.ViewFeatures有了这个包问题就消失了

© www.soinside.com 2019 - 2024. All rights reserved.