Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Up ReactJS on .NET Core 2.0, InvalidOperationException

I'm in the process of creating a basic .NET Core 2.0 App

[New]-[Project]-[.NET Core]->[ASP.NET Core Web Application (.NET Core)]-[Web Application (No Auth)]

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.

Despite my many searches both here and abroad I've come empty-handed, so I reach out to you all here. If this is referenced or already resolved here, please let me know as well.

I'm hoping I'm just overlooking something here.

Assumptions:

  • ReactJS 3.1.0 works with Core 2.0 because of 3.0.0 update (https://reactjs.net/2016/10/3.0.0-release.html)
  • Visual Studio 2017 Preview (Version 15.3) is viable for ReactJS 3.1.0 (https://reactjs.net/2017/07/3.1.0-release.html mentions 2017 tooling, which isn't enough but thought it could be perhaps?)


Update:

It turns out the problem was that there was a mismatch between the version of React that I had previously installed, and the Visual Studio Project's stated React version.
The solution was a simple reinstall of React via the command line to align with the project.

Thanks for all the help!

like image 571
WaldoFoundGodot Avatar asked Jul 24 '17 19:07

WaldoFoundGodot


1 Answers

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();

I also had to update/upgrade my node to c6.11.2 (via MSI), but I dont think thats related to your problem.

like image 118
BozoJoe Avatar answered Oct 21 '22 04:10

BozoJoe