2016-08-27 21 views
-3

我正在學習ASP.NET,而在幾個月前我需要這個部分(之後暫停)的地方,它現在顯示錯誤/警告。這是一個非常基本的.NET核心應用程序。我一無所知錯誤 看源代碼在ConfigureServices MVC中獲取'模糊調用'錯誤/警告

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?}"); 
      }); 
     } 
    } 
} 

截圖錯誤:

enter image description here

回答

0

給對象的完整名稱命名空間

例如

Microsoft.Extensions.DependencyInjection.OptionConfigurationServiceCollectionExtension 

或把你的光標放在Co nfigure < MyOptions>

和ALT + SHIFT + F10

,並選擇相應的型號。