Community
    • Login

    C# Plugin Development and Error: This ANSI plugin is not compatible with your Unicode Notepad++

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    9 Posts 6 Posters 980 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Paul BakerP
      Paul Baker
      last edited by

      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:

      1. Clone https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net.git
      2. Comment out line 165 in file: NppManagedPluginDemo.csproj (see below)
        This is because my plugin folder is write protected…
      3. Build the plugin
      4. Create a Demo folder in the NPP plugin folder and copy the dll to the new folder.
      5. Launch NPP
      6. 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 BakerP 1 Reply Last reply Reply Quote 1
      • Paul BakerP
        Paul Baker @Paul Baker
        last edited by

        @Paul-Baker
        Note: when I cloned the repo in VS, I was prompted to update the Target framework to .NET Framework 4.8.

        1 Reply Last reply Reply Quote 0
        • CoisesC
          Coises
          last edited by

          @Paul-Baker

          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.)

          Paul BakerP 1 Reply Last reply Reply Quote 2
          • Paul BakerP
            Paul Baker @Coises
            last edited by

            @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!

            1 Reply Last reply Reply Quote 2
            • Paul BakerP
              Paul Baker
              last edited by Paul Baker

              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>
              
              
              B 1 Reply Last reply Reply Quote 2
              • B
                bhu1st @Paul Baker
                last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • Mark OlsonM
                  Mark Olson
                  last edited by Mark Olson

                  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.

                  1 Reply Last reply Reply Quote 3
                  • Guido ThelenG
                    Guido Thelen
                    last edited by

                    Hi,
                    did you install the C++ development tools when installing Visual Studio. This is mandatory for developping the Npp Plugin.
                    Regards
                    Guido

                    1 Reply Last reply Reply Quote 1
                    • Davide PezziD
                      Davide Pezzi
                      last edited by

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors