LoginSignup
2
2

More than 5 years have passed since last update.

ASP.Net Core2.0 で ReactJS.NETを使う際にはConfigureServicesメソッドでIServiceProviderを返さないとInvalidOperationException

Posted at

ASP.Net Core2.0でReactを使おうと勉強してたら軽くハマってしまったが、エラーメッセージでググったら瞬殺でした・・・

Setting Up ReactJS on .NET Core 2.0, InvalidOperationException

以下、軽く日本語訳 + 説明

and trying to add ReactJS by following the tutorial here: (https://reactjs.net/getting-started/tutorial.html)
When going through the tutorial, however, I get an "InvalidOperationException" error that says: 'Cannot resolve scoped service 'React.AspNet.HttpContextLifetimeProvider+PerRequestRegistrations' from root provider.'
Specifically the error comes from the app.UseReact(config=> ... ) section of the tutorial.

チュートリアルに従ってコーディングしてたら『app.UseReact(config=> ... )』の箇所でInvalidOperationExceptionになっちゃった ><

see https://github.com/reactjs/React.NET/issues/433
change in Startup.cs
public void ConfigureServices(IServiceCollection services)
to
public IServiceProvider ConfigureServices(IServiceCollection services)
and return services.BuildServiceProvider();

これをみてごらん
Error on startup in core 2.0 'React.AspNet.HttpContextLifetimeProvider` #433

Startup.csのConfigureServicesの返り値をIServiceProvider にして
services.BuildServiceProvider()を返すんだ。

Before

Startup.cs
public void ConfigureServices(IServiceCollection services)
{
}

After

Startup.cs
public IServiceProvider ConfigureServices(IServiceCollection services)
{
    return services.BuildServiceProvider();
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2