Skip to content

Problem with initialization on azure web app #240

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

Closed
tanorion opened this issue Mar 8, 2016 · 14 comments
Closed

Problem with initialization on azure web app #240

tanorion opened this issue Mar 8, 2016 · 14 comments

Comments

@tanorion
Copy link

tanorion commented Mar 8, 2016

I have a problem with getting react.net to initialize on an azure web app. The problem occurs if I add the react nuget package after I have deployed the site the first time. I think this has to do with how azure web apps restart and store temporary files. I manage to recreate this locally and the solution then was to do an IIS reset and remove temporary asp.net files which I have not been able to do in azure. I have tried every hack for this I could find but no luck. In the end I solved this by adding the HTTPmodule in the web.config

    <httpModules>
      <add name="IocPerRequestDisposal" type="React.Web.WebInitializer.IocPerRequestDisposal"/>
    </httpModules>

And initializing the react ioc container and config in one of my other initializers.

Initializer.Initialize(AsPerRequestSingleton);
ReactConfig.Configure();

If you have better solution it would be greatly appreciated. Otherwise might I suggest to make WebInitializer public and let override it properly if needed?

This is probably related to #191 but that issue was closed so I made new one. I did try to add owin publish, no luck and the remove owin and republish, still not working.

@Daniel15
Copy link
Member

Daniel15 commented Apr 7, 2016

Interesting, not sure why adding the IocPerRequestDisposal in the Web.config would solve it. I dynamically register that module (see

DynamicModuleUtility.RegisterModule(typeof(IocPerRequestDisposal));
), perhaps that's not working properly on Azure. I do know people have gotten ReactJS.NET working on Azure in the past.

@tanorion
Copy link
Author

tanorion commented Apr 9, 2016

You can get it working on azure if the package is in the application when you first release it to azure. This error occurs when you add it afterwards. As far as I can tell the reason is that dynamically registering the module will only happen on IIS start. When you deploy new code to an azure app the IIS will not restart and thus the module will not be registered. Modules in the web.config will be registered on application start which will happen when you release new code.
I haven’t found any way to trigger an IIS reset on the web app (restart or start/stop from the azure interface will not work). The only way I got this to work with dynamically registration was to remove the web app and create a new one.

@Daniel15
Copy link
Member

How do you deploy to Azure? Is there an option to recycle the app pool on deploy? That might solve the issue too.

@tanorion
Copy link
Author

tanorion commented Apr 18, 2016

Not that I know of. I do continues integration from git and have also tried a publish profile from VS. Also when I recreated this locally restarting the app pool didn't help. I needed to restart the entire IIS.

@attiqeurrehman
Copy link

@tanorion I am facing the same issue, can you please share where to put

Initializer.Initialize(AsPerRequestSingleton);
ReactConfig.Configure();

@tanorion
Copy link
Author

@attiqeurrehman I added mine to the initialization of the CMS used in the web app but I think that you should be able to add it to Global.asax Application_Start() method. Let me know it this works for you or not.

@attiqeurrehman
Copy link

@tanorion giving error on AsPerRequestSingleton parameter.

@tanorion
Copy link
Author

tanorion commented Aug 29, 2016

@attiqeurrehman What kind of error? I should mention that I had to create my own AsPerRequestSingleton class to get this to work. Here is the code.

public static TinyIoCContainer.RegisterOptions AsPerRequestSingleton(TinyIoCContainer.RegisterOptions registerOptions)
        {
            return TinyIoCContainer.RegisterOptions.ToCustomLifetimeManager(
                registerOptions,
                new HttpContextLifetimeProvider(),
                "per request singleton"
            );
        }

@attiqeurrehman
Copy link

Still same error:

MODULE_SET_RESPONSE_ERROR_STATUS

@tanorion
Copy link
Author

@attiqeurrehman Do you have a stacktrace of the actual error?

@attiqeurrehman
Copy link

This is the link for detail
http://stackoverflow.com/questions/39201987/signalr-with-azure-causes-bad-gateway-error-502

On Mon, Aug 29, 2016 at 5:13 PM, Niklas Wanngren [email protected]
wrote:

@attiqeurrehman https://github.com/attiqeurrehman Do you have a
stacktrace of the actual error?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#240 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUY167D8P25TltyW-2U9uOxfCXEar1Gks5qkszWgaJpZM4HrgjP
.

Attiqe Ur Rehman

@tanorion
Copy link
Author

tanorion commented Aug 30, 2016

@attiqeurrehman I cant see anything related from that post. Your first image tells me there is a internal server error and that the module is React.Web.WebInitializer but it doesn't really say whats wrong. In my case there was a explicit error message saying that React was not initialized and that there was no IOC container registered. You should be able to get a more detailed error message otherwise it is hard to help. Aslo from the url of the error message it looks like this error occurs on your local machine which has never been a problem in this Issue. If this is your local machine it should be solved by removing all extra code and doing a IIS reset. If the error still persists it is probably not related to this and should perhaps be put in its own post.

@motoko89
Copy link

@tanorion Hello, I tried your solution and it doesn't work because of this:
HttpException (0x80004005): Could not load type 'React.Web.WebInitializer.IocPerRequestDisposal'.

I checked and WebInitializer is not accessible because it's internal:
https://github.com/reactjs/React.NET/blob/52eddcc799dd82157fbcf47064e7b0cafd89bb9b/src/React.Web/WebInitializer.cs

I also couldn't use but <system.webServer> instead.
Also the code appears to already do what you did. Yet whenever I deploy my ASP.NET MVC5 to Azure Web service. I will most likely hit http 500/502/503 and need to manually restart the webapp many times (maybe that has nothing because it doesn't restart IIS but after a while the website works again.

So what should I do now to work around this issue?

@dustinsoftware
Copy link
Member

Closing issues older than a year, please re-open if you think this is still relevant.

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

5 participants