C# Plugin Development and Error: This ANSI plugin is not compatible with your Unicode Notepad++
-
I recently wrote my first NPP plugin in cpp+. No issues. I’m not a c++ guy and someone suggested I try c#. I did, it looks easier but I cannot find a single template that I can work with. They all give some sort of error. The best luck I’ve had is with https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net.git but when I launch NPP with the “demo.dll” plugin I receive message:
This ANSI plugin is not compatible with your Unicode Notepad++
I see lots of posts about this but I can’t find out how to fix it in C#. I’m using VS 2022. There are references to implementing a function is isUnicode and returning true. Where? Any examples?
The steps to reproduce are:
- Clone https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net.git
- Comment out line 165 in file: NppManagedPluginDemo.csproj (see below)
This is because my plugin folder is write protected… - Build the plugin
- Create a Demo folder in the NPP plugin folder and copy the dll to the new folder.
- Launch NPP
- System displays error
What do I need to do? I’m new to VS so please take that into consideration when answering.
Thank you very much!!!
Code comments out the code to copy the dll to the NPP plugin folder… This causes an error on my machine…
</ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> --->>> <!-- Import Project="$(MSBuildProjectDirectory)\PluginInfrastructure\DllExport\NppPlugin.DllExport.targets" / --> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>
-
@Paul-Baker
Note: when I cloned the repo in VS, I was prompted to update the Target framework to .NET Framework 4.8. -
I don’t know C#, but since no one else has responded yet… I did find an issue in that repository from someone else who had this problem. Be prepared — the person posting the issue behaves like a real jerk and is so busy ranting that it’s hard to read, but he appears to have solved his own problem:
https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/issues/114
It sounds like your observation about having to change the post-build step because the plugins folder is not writable might be indirectly causing this problem. See the instructions here:
https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net#how-to-debug-plugins
concerning that. (To give yourself write permissions, you’ll need to right-click the folder and choose Properties…, then the Security tab. Windows permissions are annoyingly complicated, but I think you should be able to get this to work by clicking the Edit button, selecting Users, checking the box for Full control and OK-ing your way out.)
-
@Coises said in C# Plugin Development and Error: This ANSI plugin is not compatible with your Unicode Notepad++:
It sounds like your observation about having to change the post-build step because the plugins folder is not writable might be indirectly causing this problem. See the instructions here:
First, thank you for your reply. The links you provided will help, I just now found that if I don’t comment out the line below, the plugin works fine. So, yes, it is something with that. Now I have to readup.
<Import Project="$(MSBuildProjectDirectory)\PluginInfrastructure\DllExport\NppPlugin.DllExport.targets" />
Thanks again for replying!
-
Solved
As Coises pointed out above, when I commented the post build task for exporting the dll file I was effectively bypassing an important step. The task did more than just copy the dll to the npp/plugin folder. I added a comment to the task (see below) saying the following block of code could be uncommented to do that extra copy to npp/plugins folder.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask" AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/> <Target Name="AfterBuild" DependsOnTargets="GetFrameworkPaths" > <PropertyGroup> <!-- LibToolPath is optional - it's needed to debug C++, but you can still debug the C# code without it If you don't have the C++ toolchain installed this is missing, but then you can't' debug C++ anyway --> <LibToolPath Condition="Exists('$(DevEnvDir)\..\..\VC\bin')">$(DevEnvDir)\..\..\VC\bin</LibToolPath> </PropertyGroup> <DllExportTask Platform="$(Platform)" PlatformTarget="$(PlatformTarget)" CpuType="$(CpuType)" EmitDebugSymbols="$(DebugSymbols)" DllExportAttributeAssemblyName="$(DllExportAttributeAssemblyName)" DllExportAttributeFullName="$(DllExportAttributeFullName)" Timeout="$(DllExportTimeout)" KeyContainer="$(KeyContainerName)$(AssemblyKeyContainerName)" KeyFile="$(KeyOriginatorFile)" ProjectDirectory="$(MSBuildProjectDirectory)" InputFileName="$(TargetPath)" FrameworkPath="$(TargetedFrameworkDir);$(TargetFrameworkDirectory)" LibToolPath="$(LibToolPath)" LibToolDllPath="$(DevEnvDir)" SdkPath="$(SDK40ToolsPath)"/> <!-- $(MSBuildProgramFiles32) points to the 32 bit program files dir. On 32 bit windows usually C:\Program Files\ On 64 bit windows usually C:\Program Files (x86)\ $(ProgramW6432) points to the 64bit Program Files (on 32 bit windows it is blank) --> <!-- Uncomment the following block to copy the dll to your NPP plugin folder. --> <!-- Steps below will identify notepad++ location. It will create a "Demo" --> <!-- directory in the plugin folder and then copy the dll to it. --> <!-- <MakeDir Directories="$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\') AND !Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x86'" /> <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x86'" ContinueOnError="false" /> <MakeDir Directories="$(ProgramW6432)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(ProgramW6432)\Notepad++\plugins\') AND !Exists('$(ProgramW6432)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x64'" /> <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(ProgramW6432)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(ProgramW6432)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x64'" ContinueOnError="false" /> --> </Target> </Project>
-
@Paul-Baker said in C# Plugin Development and Error: This ANSI plugin is not compatible with your Unicode Notepad++:
SdkPath=“$(SDK40ToolsPath)”/>
Hi Paul, I am seeing a similar issue. I have the SDK40ToolsPath as
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\
What’s this value on your computer? Which Windows version you’re on?
Thank you for your help.
-
I can’t comment on these specific issues people are having with kbilsted’s old template, but I would strongly recommend that people use my C# plugin template (which is based on kbilsted’s) instead. I think you may find my template easier to use, especially if you plan to use third-party dependencies.
I haven’t made any changes in a couple months, but that’s just because nobody’s submitted any issues in a while.
-
Hi,
did you install the C++ development tools when installing Visual Studio. This is mandatory for developping the Npp Plugin.
Regards
Guido -
This post is deleted!