Application does not support just-in-time (JIT) error

After running any Python script (except the default one) I get the following error:

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Autodesk.AutoCAD.DatabaseServices.Transaction.CheckTopTransaction()
at Autodesk.AutoCAD.DatabaseServices.Transaction.GetObject(ObjectId id, OpenMode mode)
at Autodesk.AutoCAD.DynamoApp.Services.TraceData.RemoveTraceDataFromDocumentByBindingNodeIds(IEnumerable1 guids) at Autodesk.AutoCAD.DynamoApp.Services.TraceData.SaveTraceDataToDocument(HomeWorkspaceModel hws) at Autodesk.AutoCAD.DynamoApp.AcDynamoModel.OnRefreshCompleted(Object sender, EvaluationCompletedEventArgs e) at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at Dynamo.Graph.Workspaces.HomeWorkspaceModel.OnRefreshCompleted(EvaluationCompletedEventArgs e)
at Dynamo.Scheduler.AsyncTaskExtensions.<>c__DisplayClass3_0.b__1(AsyncTask _)
at Dynamo.Scheduler.AsyncTaskCompletedHandler.Invoke(AsyncTask asyncTask)
at Dynamo.Scheduler.AsyncTask.HandleTaskCompletion()
at Dynamo.Scheduler.DynamoScheduler.ProcessTaskInternal(AsyncTask asyncTask)
at Dynamo.Scheduler.DynamoScheduler.ProcessNextTask(Boolean waitIfTaskQueueIsEmpty)
at Autodesk.AutoCAD.DynamoApp.SchedulerThread.ExecuteInApplicationContextCallback(Object userData)
at myCallback(Void* data)
at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.ExecuteInApplicationContext(ExecuteInApplicationContextCallback callback, Object data)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at Autodesk.AutoCAD.ApplicationServices.Core.Application.raise_Idle(Object value0, EventArgs value1)
at Autodesk.AutoCAD.ApplicationServices.Core.Application.OnIdle()

etc etc.

I’ve tried disabling JIT debugger in Visual studio, and deleting debugger registries
The issue was first on Civil3d 2022, so I’ve installed 2023 and same thing.

Hi @lumoric,

Can you give a little more context for what you’re trying to do? You mentioned running the default Python script, but then also working in Visual Studio, so it’s unclear what the goal is and what tools are being used in the process.

I’ve only used Visual Studio to disable the JIT debugger, same with deleting registry entries.

So when I create a default Python script and execute it - it works fine. But as soon as I try to access Civil3D object it crashes.

for instance, i try to get an ObjectId of a input polyline


pline = IN[0]

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

out = []

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # Place your code below
            # 
            #
            out.append(pline.ObjectId)
            # Commit before end transaction
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = out

or this script also gives that error

Dynamo gives this error
image

If you’re just trying to run a Python script in Dynamo, then I don’t think Visual Studio has any part in this. Unless you’re building Dynamo itself from source and debugging from Visual Studio.

Assuming the pline object is a Dynamo polyline, then this code will fail because the object doesn’t have an ObjectId property. You need to unwrap it first to get to the DatabaseServices object.

This code was likely written back when the Python implementation used by the Dynamo team was IronPython, which supported brackets for indexing (for example bt[BlockTableRecord.ModelSpace]). Dynamo now uses Python.NET, which handles virtual indexers differently.

I’ve tried disabling it in VS because of this post

all of your points are valid, but my code does not only fail - it crashes. I’ve tried numerous various python scripts out there, and they all cause JIT to crash.

I’ve now done a clean uninstall of all Civil3d and Autocad, uninstalled VisualStudio and NetFramework4.8. Then reinstalled Civil3d 2022 and that did it. Not sure what was the issue.

Thanks for your efforts.

1 Like

I was hasty, nothing is resolved.
I’m really curious is this normal in Dynamo for Civil3D. I have experience with Dynamo for Revit, and it does not crash if the python code is wrong - it just gives you that classic yellow pop up we all know and hate.

So again, for instance, this code crashes with the same JIT error. I feed it simple TinSurface i select and try to extract contours.

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
surface = IN[0]
output = []

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # Place your code below
            # 
            #
            contourInterval = 50.0
            contours = surface.ExtractContours(contourInterval)
            output.append(contours.Count)
            # Commit before end transaction
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = output

Is it normal for it to crash? Or do you guys get a normal Dynamo warning? It’s really demotivating to develop python scripts if a smallest error will crash.

Hi
You can write your code inside code at link

Hi,
IronPython call Dispose() automatically for something when exiting the with block. This is not the case for Python.NET with CPython3 engine.
A correction was made by Team Dynamo, but the error handling seems buggy.

I’m not a Civil3D user, but while waiting for the bug fix, here are some solutions

  • use IronPython (why not ¯\(ツ)/¯ )
  • use a try except block after with db.TransactionManager.StartTransaction() as t: and redirect the error to the OUT variable or in the Dynamo Console with print()
  • use a context manager to handle and swallow errors

an example of context manager (need to be improve)

import sys
import clr
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

class ErrorContextManager:
    def __init__(self):
        self.typeError = None
        self.tracebackError = None
        
    def __enter__(self):
        return self
        
    def __exit__(self, exc_type, exc_value, exc_tb):
        if exc_type:
            error = "{} at line {}\n".format( exc_value, exc_tb.tb_lineno)
            self.typeError = exc_type.__name__
            self.tracebackError = error
        return self
        
    def CheckError(self):
        assert self.typeError is None, "{} : {}".format(self.typeError, self.tracebackError)
    
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
tv = []

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            with ErrorContextManager() as sc:
                bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
                btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
                for oid in btr:
                    bl = t.GetObject(oid, OpenMode.ForRead)
                    if isinstance(bl, DBText):
                        tv.append(bl.TextString)
                    
                    
            t.Commit()
sc.CheckError()
OUT = tv
2 Likes

This works for me, thanks

I’m still curious is the crash happening to everyone using CPython? Like, a typo error in code and Civil3d crashes?

Hi @lumoric,
Any other solution since then?
I have the same issue, it’s very annoying. I had a full system reinstallation because of this problem and it didn’t help.

Hi Denes,

nope, I’m using IronPython as @c.poupin suggested and it works fine.

cheers.

And do you know how can I install IronPython2 engine? Because I switched to it in Python script node and that gave me the following error message: “The selected Python engine could not be found”