React.NET: JSX on-the-fly compilation results in AccessViolationException on ASP.NET 5 MVC 6
I get the following exception whenever I try to load a .jsx file:
System.AccessViolationException was unhandled Message: An unhandled exception of type ‘System.AccessViolationException’ occurred in MsieJavaScriptEngine.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I followed the guide on Getting Started on ASP.NET 5 on a new MVC 6 project.
The really strange thing is that I don’t know how I can make the error disappear, but when I do, it won’t reappear until I clean the project. Sometimes it’s hard to get rid of, other times it’s gone after a few tries.
I have even seen it start working without the script being added to the configuration. Right now my config has:
config
.AddScript("~/lib/react/react.js")
.AddScript("~/lib/react/react-dom.js")
.AddScript("~/lib/react/react-dom-server.js")
.AddScript("~/app/app.jsx");
I know this issue is probably related to #28, but either something is missing from the guide, or something should be fixed.
Update 1:
After looking round further, it seems that MsieJavaScriptEngine.dll is the culprit. I updated my config with .SetAllowMsieEngine(false), and installed JavaScriptEngineSwitcher.V8. Still, I get that the directory bin\Debug\net461\win7-x64\ClearScript.V8 is missing. When I look in bin\Debug\net461\win7-x64\ I see ClearScript.dll, so I don’t get why it wants to look in that folder.
Update 2:
I tried adding the folder bin\Debug\net461\win7-x64\ClearScript.V8, but of course this gives another error. How do I get V8 working?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 30 (10 by maintainers)
I’ve seen this error myself several times, but only when using the MSIE JS Engine. I reported it to the developer of the MSIE JS engine library here: https://github.com/Taritsyn/MsieJavaScriptEngine/issues/7
As for getting ClearScript working, several people have done that with ASP.NET Core in the past, I haven’t tried it myself recently though. Here’s an example where @samppis got ASP.NET 5 + ReactJS.NET + ClearScript running on Azure: https://github.com/reactjs/React.NET/issues/198 along with his blog post at http://www.samulihaverinen.com/web-development/dotnet/2016/01/19/how-to-run-clearscript-v8-javascript-engine-in-azure/ and the documentation he wrote at http://reactjs.net/guides/azure.html
That was around either Beta 8 or RC1 though. If I get some free time, I’ll see if anything has changed with RC2 that would cause this to break.
Sorry I took so long to get around to this issue! I’ve been pretty busy 😞
I just wrote a blog post summarising this issue: http://reactjs.net/2016/08/protected-memory-exceptions-and-dotnet-core.html. Basically, switching to V8 appears to fix the issue in every case I’ve seen. It’s bit tricky for ASP.NET Core projects as you need to update them to properly copy over the
ClearScript.V8directory, but I’ve included instructions in the blog post. Luckily, that issue will go away with JavaScriptEngineSwitcher 2.0, which will handle this in a different way.I’m going to close out this issue due to the fact that I haven’t seen it occur at all once switched to V8 instead of MSIE. Please feel free to reopen it if you still see this exception even after switching to V8. For instructions on how to use V8, refer to the site at http://reactjs.net/2016/08/protected-memory-exceptions-and-dotnet-core.html.