1

I'm developing asp.net core application + IronPython. But I've faced with the debugging issue...

So for example I have following code:

Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine engine = Python.CreateEngine(options);

// output redirect
var eIO = engine.Runtime.IO;

var errors = new MemoryStream();
eIO.SetErrorOutput(errors, Encoding.Default);

var result = new MemoryStream();
eIO.SetOutput(result, Encoding.Default);

// execute script
ScriptScope scope = engine.CreateScope();
scope.SetVariable("testGlobalVar", 10);
engine.ExecuteFile(ScriptPath, scope);

in python file

some = "Test"

print(Test)
print("We have ->", testGlobalVar)

It works fine, but I don't know how to set breakpoint in python file and debug it step by step in Visual Studio, Pycharm(whatever), when running it via C#.

I found this question but it's almost completely useless. I'm setting breakpoint in python file and nothing happens.

smokeelow
  • 85
  • 1
  • 10
  • Which version of VS are you using? –  Apr 03 '19 at 20:45
  • I'm using Visual Studio 2019 – smokeelow Apr 03 '19 at 21:07
  • After you set breakpoint on it, and choose Start Debugging(F5), anything happens? Please check your python environments in Solution Explorer to make sure the environment is OK. – LoLance Apr 04 '19 at 08:33
  • Breakpoints works only for C# code, for python it says "the breakpoint will not currently be hit. no symbols have been loaded for this document". @LanceLi-MSFT can you send screenshots how everything must be configured? This is what i have https://monosnap.com/file/JarPr2hOfdTXqP7oPUoMdjXyAVPRmf – smokeelow Apr 04 '19 at 09:23
  • Do you start debugging under debug mode? And what the result if you create a new IronPython project, add breakpoint and debug it? can it succeed? – LoLance Apr 05 '19 at 10:32
  • @LanceLi-MSFT yes, i do it in debug mode. If i creating new IronPython without .net core projects, it works ok. But in embedded style not. – smokeelow Apr 05 '19 at 11:13
  • Not sure about the cause but I guess this issue may have something to do with the way you load the .py file. – LoLance Apr 09 '19 at 09:24

1 Answers1

1

Since it works well without debug mode as you mentioned. I think the reason for why the breakpoint won't be hit in debug mode is debugger can't find it.

Please Go=>Debug=>Options=>Uncheck Enable Just My Code to check if it helps.

Note:

  1. Set the .net core app as startup project

  2. If the uncheck Enable Just My Code not help, I suggest you go tools->Import/Export Settings->reset all settings, then uncheck the Enable Just My Code again.

After that, the breakpoint can be hit like below:

enter image description here

In addition: I use the .net console app to reproduce and test, but I think it has similar behavior like web-app. Any update feel free to contact me :)

LoLance
  • 25,666
  • 1
  • 39
  • 73