2017-09-28 23 views
3

今日私は自分のアプリケーションに本当に奇妙な問題があります。私はそれを別のフォルダに移動し、コマンドラインネットを実行すると、エラーが発生しました。Dotnet runとSystem.TypeLoadException

Unhandled Exception: System.TypeLoadException: Method 'get_Name' in type 'Micros 
oft.Extensions.Options.ConfigurationChangeTokenSource`1' from assembly 'Microsof 
t.Extensions.Options.ConfigurationExtensions, Version=1.1.2.0, Culture=neutral, 
PublicKeyToken=adb9793829ddae60' does not have an implementation. 
    at Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollec 
tionExtensions.Configure[TOptions](IServiceCollection services, IConfiguration c 
onfig) 
    at LicenseManager.Api.Startup.ConfigureServices(IServiceCollection services) 
in D:\Projekty\LicenseManager\src\LicenseManager.Api\Startup.cs:line 61 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(ISer 
viceCollection services) 
    at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() 
    at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() 
    at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 
    at LicenseManager.Api.Program.Main(String[] args) in D:\Projekty\LicenseManag 
er\src\LicenseManager.Api\Program.cs:line 15 

移動する前にエラーが発生しました。ここで

が私のスタートアップクラスです:

public class Startup 
    { 
     public Startup(IHostingEnvironment env) 
     { 
      var builder = new ConfigurationBuilder() 
       .SetBasePath(env.ContentRootPath) 
       .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 
       .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
       .AddEnvironmentVariables(); 
      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) 
     { 
      // Add framework services. 
      services.AddMvc() 
        .AddJsonOptions(x => x.SerializerSettings.Formatting = Formatting.Indented); 
      services.AddCors(o => o.AddPolicy("DefaultPolicy", builder => 
      { 
       builder.AllowAnyOrigin(); 
       builder.AllowAnyMethod(); 
       builder.AllowAnyHeader(); 
      })); 
      services.AddScoped<IComputerRepository, InMemoryComputerRepository>(); 
      services.AddScoped<ILicenseRepository, InMemoryLicenseRepository>(); 
      services.AddScoped<ILicenseTypeRepository, InMemoryLicenseTypeRepository>(); 
      services.AddScoped<IRoomRepository, InMemoryRoomRepository>(); 
      services.AddScoped<IUserRepository, InMemoryUserRepository>(); 
      services.AddScoped<IRoomService, RoomService>(); 
      services.AddScoped<ILicenseTypeService, LicenseTypeService>(); 
      services.AddScoped<IUserService, UserService>(); 
      services.AddScoped<ILicenseService, LicenseService>(); 
      services.AddScoped<IComputerService, ComputerService>(); 
      services.AddScoped<IDataInitializer,DataInitializer>(); 
      services.AddSingleton(AutoMapperConfig.Initialize()); 
      services.Configure<AppSettings>(Configuration.GetSection("app")); 


     } 

     // 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.UseCors("DefaultPolicy"); 
      app.UseCors(builder => 
       builder.WithOrigins("http://localhost:5050").AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()); 
      loggerFactory.AddNLog(); 
      app.AddNLogWeb(); 
      env.ConfigureNLog("nlog.config"); 
      SeedData(app); 

      app.UseMvc(); 

     } 

     private void SeedData(IApplicationBuilder app) 
     { 
      var settings = app.ApplicationServices.GetService<IOptions<AppSettings>>(); 
      if(settings.Value.SeedData) 
      { 
       var dataInitializer = app.ApplicationServices.GetService<IDataInitializer>(); 
       dataInitializer.SeedAsync(); 
      } 
     } 
    } 

私は

services.Configure<AppSettings>(Configuration.GetSection("app")); 

あるライン61をコメントしようとしましたが、アプリケーションは私に別のTypeLoadExceptionを与えました。 私はそれをgithubにプッシュすると同じことです。

答えて

0

設定の問題が読み込まれているようです。 アプリをどのように実行しますか?エントリーポイントはどこですか? cdを使用してプロジェクトの "go into"ディレクトリに移動するか、 "dotnet run my/test/project"を使用しますか?あなたは、あなたがそれを使用する.csprojとディレクトリにある必要がありますので、あなたが現在置かれているディレクトリ、または2番目のオプションを取得する)

.SetBasePath(env.ContentRootPath) 

.SetBasePath(Directory.GetCurrentDirectory()) 
.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)) 

にDirectory.GetCurrentDirectoryを(変更することができます。出力中の設定ファイルを検索します。

+0

答えていただきありがとうございますが、アプリケーションには私のappsettingsファイルが表示されません。設定ファイル 'appsettings.json'が見つかりませんでした。これはオプションではありません。私はアプリケーションのフォルダ内でcdコマンドでプログラムを実行しています。 – Kerni

2

私は

<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> 
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.0" /> 
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" /> 

そして今、DOTNET、私csprojに2つの参照を追加し、実行は作業を開始するが、私は、例えば、送信するときにHttp.Getはチョウゲンボウを要求する私にこのメッセージを送る:

2017-09-28 10:52:28.8575|WARN|Microsoft.AspNetCore.Server.Kestrel|Connection processing ended abnormally. 

EDITを

Finnalyアプリケーションが動作する新しいNLog.Extensions.Loggingパッケージのバージョン1.0.0-rtm-beta6で問題が発生しました。私はバージョン1.0.0-rtm-beta5に戻った。そして、アプリケーションは作業を開始します。

関連する問題