React.NET icon indicating copy to clipboard operation
React.NET copied to clipboard

ASP.NET Core 1.1 & ReactJS

Open DaveKP opened this issue 10 years ago • 13 comments

Couldn't find a better place to ask - Should ReactJS be working with .net Core 1.1?

I'm getting :

ReactNotInitialisedException: ReactJS.NET has not been initialised correctly. Please ensure you have called app.AddReact() and app.UseReact() in your Startup.cs file.

When trying to use server-side rendering.

I can't see anything that I've mis-configured though, based on the tutorial code.

Startup.cs.txt

DaveKP avatar Nov 27 '16 14:11 DaveKP

Okay, so i managed to get things working. I imported React.Core and React.AspNet from the GitHub repo. In Initialiser.cs - the IsReactAssembly() method - for me the assembly names were coming in all lower case, so I changed the string comparisons inside the method.

I haven't had time to search for why they're coming in lower case, anyone know?

I'm messing around in VS 2017 RC at the moment, so my environment's a mess - but I'll make a pull request when I have time to sort things out. It's bedtime here!

DaveKP avatar Nov 27 '16 21:11 DaveKP

Hmm strange - I'm running http://dan.cx/socialfeed.htm on Mono 4.x + ASP.NET Core 1.1 + ReactJS.NET 3.0 and it's working fine.

Daniel15 avatar Nov 27 '16 21:11 Daniel15

Hi,

I think I might have more information on this problem. I have the same exact (I am pretty sure) project (Core 1.1) in VS2015 and in VS2017 RC. I believe the only difference is that in 2017 the project is using the new csproj file format. React.Net works for me in VS2015 but in VS2017 I get the "ReactNotInitialisedException: ReactJS.NET has not been initialised correctly. Please ensure you have called app.AddReact() and app.UseReact() in your Startup.cs file." message.

chanan avatar Jan 02 '17 22:01 chanan

@chanan - Hmm, I haven't tested on VS2017 RC yet. Did you add app.AddReact and app.UseReact to your Startup.cs file like the message says? What's the full error message and stack trace you're seeing?

Daniel15 avatar Jan 02 '17 23:01 Daniel15

Yes both in VS2015 and VS2017 RC the startup and all the other files are the same.

I cant give you a stack trace now since I screw up the csproj file somehow trying to figure out how to get ReactJS.Net to work (and eventually I moved back to VS2015 on a hunch). However, in other issues posted here someone else posted a tack trace that looks like mine (at least from memory). The issue seems to be with TinyIoC.

chanan avatar Jan 02 '17 23:01 chanan

Have the same issue here using VS2017 RC + ASP.NET Core 1.1 + ReactJS.NET 3.0, I can say that the method app.AddReact() doesn't exists in the Configure section.

ghost avatar Jan 05 '17 23:01 ghost

You need to call AddReact to configure ReactJS.NET otherwise it won't work properly.

Sent from my phone.

On Jan 6, 2017 9:36 AM, "Etienne S.G" [email protected] wrote:

Have the same issue here using VS2017 RC + ASP.NET Core 1.1 + ReactJS.NET 3.0, I can say that the method app.AddReact() doesn't exists in the Configure section.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/reactjs/React.NET/issues/353#issuecomment-270789835, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFnHZwlrz_yOUzi8Yw2XNTJt9-Bnye3ks5rPX5-gaJpZM4K9Kl9 .

Daniel15 avatar Jan 05 '17 23:01 Daniel15

@Daniel15 I pasted a working code in VS2015 and the same project once upgraded to 2017 stops working. The stack trace and link to the most simple of all projects is in https://github.com/reactjs/React.NET/issues/361

chanan avatar Jan 07 '17 00:01 chanan

My Startup.cs class is the following, but I'm still getting the same error with VS2017 RC:

public class Startup
{
        public void ConfigureServices(IServiceCollection services)
        {
            // Add React
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddReact();

            // Add framework services
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseReact();
            app.UseStaticFiles();            
            app.UseMvc(routes => 
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}");
            });
    }
}

And I have the Tutorial.jsx file under wwwroot\js directory, as well has the configuration for the view from the tuturial:

@{
    Layout = null;
}
<html>
<head>
    <title>Hello React</title>
</head>
<body>
    <div id="content"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js"></script>
    <script src="@Url.Content("~/js/tutorial.jsx")"></script>
</body>
</html>

ghost avatar Jan 11 '17 19:01 ghost

Have those still encountering problems tried using the development version of ReactJS.net including #354 ?

DaveKP avatar Jan 11 '17 19:01 DaveKP

If you want to try the development version, you can use the NuGet package server on our AppVeyor build (https://ci.appveyor.com/nuget/reactjs.net/). Instructions are available at https://reactjs.net/getting-started/download.html#development-builds

I haven't had time to try VS2017 RC yet. @DaveKP Do you think that diff solves the issues with VS2017?

Daniel15 avatar Jan 11 '17 20:01 Daniel15

@Daniel15 Yes, that diff fixed the issue for me which was using VS2017. I would expect it to work for others as well, but I never did figure out exactly why it was happening.

DaveKP avatar Jan 12 '17 09:01 DaveKP

I pushed out #354 as ReactJS.NET 3.0.1. Let me know if you still encounter issues. This fix seemed to fix the issue for me.

Daniel15 avatar Feb 13 '17 05:02 Daniel15