Skip to main content
6-Contributor
August 21, 2025
Question

Mathcad Prime crashes - "An unhandled exception occured. See .log file"

  • August 21, 2025
  • 1 reply
  • 1185 views
I am using Mathcad Prime Release 10.0 and Datecode10.0.0.0

My company uses Python scripts to extract Mathcad Prime data to Excel spreadsheets. The Python code uses the MathcadPy library to extract data to the spreadsheets, but I am continually getting errors when running the code. I have also seen the error popup when running Mathcad Prime normally.
We create a folder structure of Mathcad Prime files, using relative links to point to the folder/file at the next level up. We have a number of Mathcad sheets in the same folder and they all point to Mathcad files at the directory above , to make a make-shift library of electrical parts/parameters for our application.
I will randomly see the error pop-up when accessing these files. It is also random, and there is no predictability to the error popping up.

Here are the errors that I faced
"An unhandled exception occured. See .log file"

Exception data:
System.Exception: Lisp applying: CallNodeCallback {global} to Engine.NodeCallback, 1419, NODE_READY, System.Collections.Hashtable, System.Collections.Hashtable, True, False; Collection was modified; enumeration operation may not execute. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

The following files are being opened:
... (Exception when getting files list: The calling thread cannot access this object because a different thread owns it.)

    1 reply

    6-Contributor
    August 21, 2025

    I have also attached one of the log files I get when I get this error popup.

    18-Opal
    August 22, 2025

    This error is a classic software race condition, which is happening inside Mathcad's calculation engine. It's a timing issue where one part of the program tries to read a list of items while another part is simultaneously trying to change that same list.

    The two key error messages tell the whole story:

    1. Collection was modified; enumeration operation may not execute.: This is like trying to count a list of items on a piece of paper while someone else is actively erasing and adding new items. The program stops to prevent a crash or data corruption.

    2. The calling thread cannot access this object because a different thread owns it.: This confirms it's a multi-threading problem. One process (a thread) is stepping on the toes of another, which is a common cause of race conditions.


     

    Why It's Happening in Your Case

     

    Your setup, which involves a complex structure of linked worksheets with relative paths and automation via a Python script, is the perfect environment for this bug to surface.

    • When you open a Mathcad file, its calculation engine starts analyzing all the linked files ("includes" or "libraries") to figure out what needs to be calculated.

    • Your Python script, using MathcadPy, is likely opening, reading, and possibly modifying these files very quickly.

    • This rapid file access from your script conflicts with Mathcad's own background process that is trying to manage the file dependencies. The two processes "race," and sometimes your script modifies the file list just as the calculation engine is trying to read it, causing the crash.

    The randomness occurs because it depends on the precise millisecond timing of your computer's operations, network speed (since you're on a corporate network), and file I/O, which can change every time you run the script.


     

     

     

    Here are several strategies, from simplest to most involved, to resolve this issue.

     

    1. Slow Down Your Python Script

     

    This is the most likely and easiest fix. The script is probably overwhelming Mathcad's file handling. Add a short delay after opening a file and before triggering a calculation or saving.

    In your Python script, add a small sleep after each significant Mathcad operation (like opening a file):

    Python
     
    import time
    
    # Example within your script loop
    mc.open('C:\\path\\to\\your\\file.mcdx')
    time.sleep(2) # Pauses the script for 2 seconds
    # Now proceed with getting values, calculating, etc.
    
     
     
     
     
     

    A 1 or 2-second pause is often enough to let Mathcad's engine stabilize before you ask it to do the next thing.

     

    2. Work Locally

     

    Your environment variables show you're using OneDrive and a corporate domain (goldlnk.rootlnka.net). Network latency and file syncing can make these timing issues much worse.

    Before running your script, try copying the entire folder structure from the network/OneDrive location to a simple, local folder (e.g., C:\Mathcad_Temp\). Run the script on the local files. This eliminates network lag as a variable.

     

    3. Simplify File Linking

     

    Deeply nested relative paths (../../library/file.mcdx) can sometimes be harder for applications to track reliably.

    • Use the "Include Worksheet" Feature: Instead of just referencing variables from other files, consider using Mathcad's dedicated Insert > Include Worksheet feature. It can sometimes be more stable.

    • Flatten Your Directory: If possible, reduce the number of parent directory (..) lookups. A flatter structure might be easier for the calculation engine to manage.

     

    4. Check for a Mathcad Update

     

    You are on version 10.0.0.0. This kind of bug is often fixed in subsequent maintenance releases (e.g., 10.0.1.0 or similar). Check the PTC support website for any available updates for Mathcad Prime 10, as they may have already patched this specific race condition.

     

    5. Contact PTC Support

     

    If none of the above solutions work, this is a bug within Mathcad Prime. Provide PTC support with the exact log file you've shared. This detailed information is exactly what their developers need to identify and fix the root cause in a future update.

    6-Contributor
    August 22, 2025

    Thank you so much. This is very helpful.

     

    I will try to slow down the scripts to allow for Mathcad to stabilize before trying to access the data.