Script Engine Exception. A ScriptEngine threw exception 'C0000005' in 'IActiveScript::SetScriptState()' from 'CActiveScriptEngine::ReuseEngine()
Issue description:
You may encounter issues when using the jscript9legacy.dll (JScript 9) JavaScript engine with Classic ASP, resulting in a Script Engine Exception. Specifically, the error message:
A ScriptEngine threw exception 'C0000005' in 'IActiveScript::SetScriptState()' from 'CActiveScriptEngine::ReuseEngine()'
indicates an access violation during script state transition. This typically occurs due to compatibility limitations between Classic ASP and the newer jscript9legacy.dll engine. Despite its name, jscript9legacy.dll is not fully compatible with Classic ASP and differs from the older jscript.dll (JScript 5.8), which is more stable in Classic ASP environments
You might see following error in the Event log:
Event Xml:
<Event xmlns=http://schemas.microsoft.com/win/2004/08/events/event>
<System>
<Provider Name="Active Server Pages" />
<EventID Qualifiers="49152">5</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2025-05-28T15:25:47.7068466Z" />
<EventRecordID>10933</EventRecordID>
<Correlation />
<Execution ProcessID="11336" ThreadID="0" />
<Channel>Application</Channel>
<Computer>Computer Name</Computer>
<Security />
</System>
<EventData>
<Data>File /AuroraWeb/ENT_Automation.asp Script Engine Exception. A ScriptEngine threw exception 'C0000005' in 'IActiveScript::SetScriptState()' from 'CActiveScriptEngine::ReuseEngine()'.</Data>
</EventData>
</Event>
More about the JavaScript libraries for Classic ASP:
jscrip9legacy is a newer engine than jscrip9legacy, don’t confuse it with the word ‘legacy’ in jscrip9legacy.
- jscript.dll (Jscript 5.8) = older, compatible with Classic ASP (The real legacy dll)
- jscript9legacy.dll (Jscript 9) = newer, but less compatible with Classic ASP (The fake legacy dll 😊)
The "legacy" label here refers to its role in maintaining compatibility with legacy websites (not Classic ASP) within the Internet Explorer context.
In details:
- jscript.dll refers to the classic JScript engine (version 5.8), which is what Classic ASP was originally built to run on. This engine supports legacy constructs and behavior expected by older scripts and COM interactions.
- jscript9.dll / jscript9legacy.dll is part of the JScript9 engine, introduced with Internet Explorer 9 to modernize JavaScript support (aligning with ECMAScript 5). It is faster and more standards-compliant….but not backward-compatible with all classic JScript features.
Fix:
You have 2 ways to fix this issue:
- we need to configure the system to use the legacy JScript engine (`jscript.dll`) instead of `jscript9legacy.dll` or
- Disable JScriptReplacement in the Registry.
Approach 1: use the legacy JScript engine (`jscript.dll`) instead of `jscript9legacy.dll`
This involves modifying the Windows Registry to disable the JScript9 engine for the IIS worker process (`w3wp.exe`).
Here are the steps to follow:
- Open the Registry Editor (regedit).
- Navigate to the following key:
`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_JSCRIPT9_LEGACY`
- Create a new DWORD (32-bit) value named `w3wp.exe`.
- Set its value to `0`.
- For 32-bit systems or applications, also navigate to:
`HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ENABLE_JSCRIPT9_LEGACY`
- Repeat steps 3 and 4 in this location.
- After making these changes, restart IIS to apply the new settings.
Approach 2: Disable JScriptReplacement in the Registry
This involves modifying the Windows Registry to disable the JScript9 engine for the IIS worker process (`w3wp.exe`).
Here are the steps to follow:
- Open the Registry Editor (regedit).
- Navigate to the following key: `HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main`
- Create a new DWORD (32-bit) value named `JScriptReplacement`.
- Set its value to `0`.
- For 32-bit systems or applications, also navigate to:
`HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Policies\Microsoft\Internet Explorer\Main`
- Repeat steps 3 and 4 in this location.
- After making these changes, restart IIS to apply the new settings.
After the above changes, the issue must have been fixed.
Both FEATURE_ENABLE_JSCRIPT9_LEGACY and JScriptReplacement can be used to control the behavior of the JScript engine on Windows, but they differ in scope, intent, and implementation.
FEATURE_ENABLE_JSCRIPT9_LEGACY is a feature control setting that applies on a per process basis, allowing you to disable JScript9 for specific executables like w3wp.exe. In contrast, JScriptReplacement is a policy-based setting that disables JScript9 system wide, applying broadly to all processes.
I hope this helps.