【问题标题】:Getting 'ambiguous call' error/warning in ConfigureServices MVC在 ConfigureServices MVC 中获取“模糊调用”错误/警告
【发布时间】:2016-08-27 09:47:58
【问题描述】:

我正在学习 ASP.NET,而几个月前我在某个地方需要这部分(之后暂停),它现在显示错误/警告。这是一个非常基础的 .NET Core 应用程序。我对错误一无所知 查看源代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace WebApplication1
{

    public class MyOptions
    {
        public string color { get; set; }
        public string welcomestring { get; set; }
    }

    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();
            if (env.IsDevelopment())
            { 
                builder.AddUserSecrets();
            }
                if (env.IsDevelopment())
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<MyOptions>(Configuration);
            var foo = Configuration["welcomestring"];
            Console.WriteLine(foo);
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

错误截图:

【问题讨论】:

    标签: asp.net .net asp.net-mvc asp.net-mvc-5


    【解决方案1】:

    给出具有命名空间的对象的完整名称

    例子

    Microsoft.Extensions.DependencyInjection.OptionConfigurationServiceCollectionExtension
    

    或将光标放在 Configure

    和 ALT + SHIFT + F10

    并选择您的型号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2018-10-15
      • 1970-01-01
      相关资源
      最近更新 更多