Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core 1.1 & ReactJS #353

Closed
DaveKP opened this issue Nov 27, 2016 · 13 comments
Closed

ASP.NET Core 1.1 & ReactJS #353

DaveKP opened this issue Nov 27, 2016 · 13 comments

Comments

@DaveKP
Copy link
Contributor

DaveKP commented Nov 27, 2016

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
Copy link
Contributor Author

DaveKP commented Nov 27, 2016

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!

@Daniel15
Copy link
Member

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.

@chanan
Copy link

chanan commented Jan 2, 2017

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.

@Daniel15
Copy link
Member

Daniel15 commented Jan 2, 2017

@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?

@chanan
Copy link

chanan commented Jan 2, 2017

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.

@ghost
Copy link

ghost commented Jan 5, 2017

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.

@Daniel15
Copy link
Member

Daniel15 commented Jan 5, 2017 via email

@chanan
Copy link

chanan commented Jan 7, 2017

@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 #361

@ghost
Copy link

ghost commented Jan 11, 2017

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>

@DaveKP
Copy link
Contributor Author

DaveKP commented Jan 11, 2017

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

@Daniel15
Copy link
Member

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?

@DaveKP
Copy link
Contributor Author

DaveKP commented Jan 12, 2017

@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.

@Daniel15
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants