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.

7
  • Which version of VS are you using? Commented Apr 3, 2019 at 20:45
  • I'm using Visual Studio 2019 Commented Apr 3, 2019 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. Commented Apr 4, 2019 at 8: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 monosnap.com/file/JarPr2hOfdTXqP7oPUoMdjXyAVPRmf Commented Apr 4, 2019 at 9: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? Commented Apr 5, 2019 at 10:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to know my answer helps :) Have a nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.