0

Our codebase is written mostly in C# with some scripting capabilities using IronPython 3.4. Until recently we based the project on the outdated .Net Framework 4.8 but made the move to .Net 8 recently.

One odd thing is bugging us: With .Net Framework as a target we could load the python script files in Visual Studio and set breakpoints which nicely triggered when the script was executed. After the shift to .Net 8 this does not work any longer.

I created a minimal working example to confirm this behavior:

using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Runtime;
using System;
using System.Collections.Generic;

namespace ScriptTest
{
    internal class Program
    {
        static void Main(string[] args) {
            ScriptEngine pythonEngine = null;
            ScriptScope pythonScope = null;

            Dictionary<string, object> options = new Dictionary<string, object>();
            options["Debug"] = ScriptingRuntimeHelpers.True;

            pythonEngine = Python.CreateEngine(options);
            pythonScope = pythonEngine.CreateScope();

            ScriptSource pythonSrc = pythonEngine.CreateScriptSourceFromFile(@".\Test.py");
            CompiledCode compiled = pythonSrc.Compile();
            compiled.Execute(pythonScope);
        }
    }
}

with the following very simple Test.py file:

print('Test')

One thing I noticed is that with the .Net Framework version a symbol "file" called Snippets.debug.scripting is loaded a soon as the Python script is ececuted. This does not happen in the .Net 8 version.

Any ideas how to get breakpoints working with .Net 8? Maybe this is just some Visual Studio setting but I found not clue yet.

1
  • Hi @Matthias, below is my test result. snippets.debug.scripting file can be loaded with .NET 8. If the file not loaded, please check if you have enabled Enable Just My Code. Commented Aug 7, 2024 at 3:01

1 Answer 1

0

Do you mean the breakpoints in your Python file (Test.py) not hit with.Net8?

If yes, I suggest you check whether you have enabled Enable Just My Code. Please go =>Debug=>Options=>Uncheck Enable Just My Code.

If the uncheck Enable Just My Code not help, please go tools->Import/Export Settings->reset all settings, then uncheck the Enable Just My Code again to see if the issue persists.

Update

Here is my test result:

Env:

IronPython(3.4.1)
Visual Studio 2022(17.10.5)
a ClassLibrary(c#) with .NET8.0

enter image description here

Based on my test, the Python script file and snippets.debug.scripting can be loaded in Visual Studio. The Test.py file can print "test" fine. Please check if I missed something. It would be better if you share where you set breakpoints.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.