cs-script.npp: Creating a new script crashes latest 64-bit Notepad++ release
Steps to reproduce
- Install any recent 64-bit build of Notepad++
- Install CS-Script (1.7.26) from the menu at
Plugins > Plugins Admin - After N++ reloads, open the CS-Script project panel
- Select “Create new script”
- When the “New Script Name” dialog appears, click
OK:

- N++ becomes unresponsive and crashes
- Check the Windows Event Viewer for something like this:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2022-02-01T12:18:38.5097359Z" />
<EventRecordID>19526</EventRecordID>
<Correlation />
<Execution ProcessID="12456" ThreadID="0" />
<Channel>Application</Channel>
<Computer>AcerNotebook</Computer>
<Security />
</System>
<EventData>
<Data>
Application: notepad++.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: exception code c0000005, exception address 00007FF6775AEFFF
Stack: at Kbg.NppPluginNET.PluginInfrastructure.Win32.SendMessage(IntPtr, UInt32, IntPtr, IntPtr)
at Kbg.NppPluginNET.PluginInfrastructure.Win32.SendMessage(IntPtr, UInt32, IntPtr, IntPtr)
at Kbg.NppPluginNET.PluginInfrastructure.ScintillaGateway.GetTextRange(Kbg.NppPluginNET.PluginInfrastructure.TextRange)
at CSScriptIntellisense.NppExtensions.GetTextBetween(Kbg.NppPluginNET.PluginInfrastructure.ScintillaGateway, Int32, Int32)
at CSScriptNpp.CodeMapPanel.RefreshContent()
at CSScriptNpp.Plugin.OnCurrentFileChanged()
at CSScriptNpp.UnmanagedExports.beNotified(IntPtr)
at Kbg.NppPluginNET.UnmanagedExports.beNotified(IntPtr)
at Kbg.NppPluginNET.PluginInfrastructure.Win32.SendMessage(IntPtr, UInt32, IntPtr, System.String)
at Kbg.NppPluginNET.PluginInfrastructure.Win32.SendMessage(IntPtr, UInt32, IntPtr, System.String)
at CSScriptNpp.ProjectPanel.newBtn_Click(System.Object, System.EventArgs)
at System.Windows.Forms.ToolStripItem.RaiseEvent(System.Object, System.EventArgs)
at System.Windows.Forms.ToolStripButton.OnClick(System.EventArgs)
at System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs)
at System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs)
at System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ToolStrip.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
</Data>
</EventData>
</Event>
Notepad++ v8.2.2 (64-bit)
Build time : Jan 31 2022 - 14:21:55
Path : C:\Users\Rob\Downloads\dev\npp_8.2.2_rc5\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : ON
Cloud Config : OFF
OS Name : Windows 11 (64-bit)
OS Version : 2009
OS Build : 22000.469
Current ANSI codepage : 65001
Plugins : CSScriptNpp.dll mimeTools.dll NppConverter.dll NppExport.dll
_Also reported upstream at https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/issues/84_
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 25 (15 by maintainers)
Commits related to this issue
- Issue #64: `CharacterRange.cpMin` and `CharacterRange.cpMax` changed from `int` to `IntPtr` — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- - Issue #64: Creating a new script crashes latest 64-bit Notepad++ release — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- - Issue #64, #65 Added `TextRangeLegacy` to allow transparent hosting on otherwise incompatible versions of N++ — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- - Issue #64, #65: Added `TextRangeLegacy` to allow transparent hosting on otherwise incompatible versions of N++ - Some code cleanup — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- Release v1.7.28.0 ---- v1.7.28 - Patched NppPluginNet: `CharacterRange.cpMin` and `CharacterRange.cpMax` changed from `int` to `IntPtr` This addresses the problems triggered by this the third-party ... — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- Release v1.7.28.0 ---- v1.7.28-29 - Patched NppPluginNet: `CharacterRange.cpMin` and `CharacterRange.cpMax` changed from `int` to `IntPtr` This addresses the problems triggered by this the third-par... — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- - Improved Npp compatibility checking (Issue #64) Described: https://github.com/oleg-shilo/cs-script.npp/issues/64#issuecomment-1108448994 — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- Release v2.0.1.0 - Improved Npp compatibility checking (Issue #64) Described: https://github.com/oleg-shilo/cs-script.npp/issues/64#issuecomment-1108448994 — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- - Added support for new API for retrieving NPP version (triggered by #64) — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- v2.0.2.0 - Improved Npp compatibility checking (Issue #64) Described: https://github.com/oleg-shilo/cs-script.npp/issues/64#issuecomment-1120081360 — committed to oleg-shilo/cs-script.npp by oleg-shilo 2 years ago
- Update CSScriptNpp v2.0.2.0 - Improved Npp compatibility checking (Issue #64) Described: https://github.com/oleg-shilo/cs-script.npp/issues/64#issuecomment-1120081360 — committed to oleg-shilo/nppPluginList by oleg-shilo 2 years ago
- Update CSScriptNpp v2.0.2.0 (#450) * Update CSScriptNpp v2.0.2.0 - Improved Npp compatibility checking (Issue #64) Described: https://github.com/oleg-shilo/cs-script.npp/issues/64#issuecomment-1... — committed to notepad-plus-plus/nppPluginList by oleg-shilo 2 years ago
- Release v2.0.3.0 ---- - Npp compatibility checking (Issue #64) is disabled in favor of hard-codded compatibility for new Scintille.TextRange API. The checking algorithm became fragile in the latest ... — committed to oleg-shilo/cs-script.npp by oleg-shilo a year ago
Rookie mistake 😊 I just had to override the security block that Windows applies to executables from “untrusted” sources:
For reference, all of the following need unblocking as well:
Great. Thank you. And I even managed to convince N++ team to embed the compatibility metadata in the https://github.com/notepad-plus-plus/notepad-plus-plus/issues/11198
I am glad you noticed the difference between the original NppPlugin.Host architecture and the approach CS-Script.Npp has taken.
I was not satisfied with the idea of building two versions of a plugin assembly and duplicating probably 80% of the codebase. Instead, I wanted to utilize .NET offers a very natural
any CPUmodel.Thus I have created two functionally identical plugin hosting assemblies (x86 and x64) and a single AnyCPU plugin assembly to be loaded by the hosting assembly dynamically. That’s it. 😃
I even contacted the developer of the NppPlugin.Host and shared the approach. Even offered assistance with incorporating it. But it did not go any further.
That’s why this plugin also maintains the customized fork of NppPlugin.Host.
Thank you for looking into this.
You are absolutely right the crash is not reproducible in Notepad++ 8.2.1. In fact, I would advise users to resist upgrading their editors, or else use only 32-bit versions for the time being. It has happened again in the now generally available 8.3 release. The runtime version of the assembly that faulted in 8.2.2 and now 8.3 was reported as “4.0.30319” by the Windows Event Viewer(*); the same runtime target as the NppPlugin.Host assemblies:
https://github.com/oleg-shilo/cs-script.npp/blob/0b8d87b8b3946bdbe857901671e5fc4679bda4cb/src/NppPlugin.Host/NppPlugin.Host.csproj#L13
As I tried to convey in the linked issue, this is not a bug in either the plugin or the editor. The developers of N++ are well aware that the new release will be an unstable host for 64-bit plugins.
The problem goes back to a feature request against N++ to make massive files of >2GB editable. It was just barely achieved (for x64 builds only) by retyping Scintilla’s
Sci_PostionCRmessage asintptr_t, which expands to eight bytes on x86_64 architecture.The hosting model’s equivalent type,
CharacterRange, declares fields that are currently too small to safely handle the 64-bit values that calling intoSCI_GETTEXTRANGEwill now return from 64-bit editors.There’s an open PR at the hosting model’s parent repo to address multi-arch memory safety; e.g., preferring
IntPtrtointfor types exposed to unmanaged interactions with Scintilla’s API. As you rightly suggested earlier, this will be no help, assuming it ever gets merged. There is no drop-in replacement for cs-script’s heavily customized hosting model.I can confirm that a patched plugin can be safely loaded by even a pre-release editor once the
structdeclaration near line 214 ofNppPlugin.Host/PluginInfrastructure/GatewayDomain.csis changed to useIntPtrfor thecpminandcpmaxfields, with the other type changes that entails. Notice the type and bit width of each member in the watch list below:These will be sized accordingly in 32-bit builds, so backward compatibility isn’t affected:
I can’t predict if there will be regressions; that should be weighed against the current risk of losing data to an application crash.
(*)