oleg-shilo / cs-script.npp

CS-Script (C# Intellisense) plugin for Notepad++ (x86/x64)
MIT License
246 stars 52 forks source link

using script config in notepad++ debugger not working #38

Closed KG2501 closed 7 months ago

KG2501 commented 5 years ago

Debugging a script that is using a script config file .cs.config does not work, because the config file is not loaded. The debugger is always loading the C:\Program Files\Notepad++\plugins\CSScriptNpp\CSScriptNpp\css_dbg.exe.config which does not exists. Why isn't it loading the script config file which is in the same directory as the script file? In the C:\Program Files\Notepad++\plugins\CSScriptNpp\CSScriptNpp is no css_config.xml file. Can this be a problem? I'm using notepad++ 7.6.6 (64bit) with CSScriptNpp 1.7.24

thanks for any help.

oleg-shilo commented 5 years ago

Unfortunately it's not an easy to fix problem. CLR is ultimately inflexible when it comes to loading config files. Basically it is the entry assembly file name + .config.

In cs-script the problem is solved by loading the script is a separate AppDomain and configuring this appdomain to use alternative config file.

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile = configFile;

It is a heavy trick that btw does not work on .NET core as its AppDomain config simply does not allow alternative "*.config" at all.

Thus as a rule of thumb I am trying to avoid using .config and use .json settings files instead.

Anyway, it looks like the trick does not work in case of debugging (being executed by the css_dbg.exe).

I will check if AppDomain.CurrentDomain.SetupInformation.ConfigurationFile is accidentally not set in case of debugging. But to be honest the chances of that are slim.

In a mean time you can use an alternative debugging technique when you start the script as normal and only attach the debugger when it is fully loaded. You can do it by using Assert statement.