Winerror with comtypes python package in Grasshopper/Rhino 8 + Solution

Hello everyone,

I recently encountered a technical hiccup while migrating my Rhino 7 C# component scripts to Python scripts in Grasshopper for Rhino 8.

Problem:

Obscure windows error while getting running instances as an object using comtypes

the script in question had a python component that is used to get a running instance of a software (CSI ETABS in my case) and passes it as an object to other pieces of the script, the code:

      #r: comtypes
      import comtypes
      helper = comtypes.client.CreateObject('...')

In doing that, I kept getting a Windows error with an obscure error code at line 3:

Error running script: [WinError -2147450715] Windows Error 0x800080a5 [4:1]

Troubleshooting: TLDR: skip to solution.

After a good hour doing tests in grasshopper python, C# and standalone python, and another good portion of an hour reading through comtypes documentation, windows COM generic errors, installing comtypes manually using pip and searching online, I found a post on stackoverflow with the same error code, but the problem was in .NET 6 and the solution is irrelevant to python. However, the answer included using a tool called DebugView by microsoft that lets you monitor debug output for Win32.

By downloading and running the tool, then running my error-causing script, the error was translated to:

[17036] The specified framework 'Microsoft.NETCore.App', version '8.0.0', apply_patches=1, version_compatibility_range=minor is incompatible with the previously loaded version '7.0.20'.

I had stumbled on the following page in the Rhino developer guides explaining the Rhino 8 is defaulting to .Net Core with the option to use .Net Framework.

Solution:

Switch your Rhino to .Net Framework from .Net Core as per this guide.

  1. Run SetDotNetRuntime command in Rhino.
  2. Select the Runtime option.
  3. Set the NETFramework option.
  4. Restart Rhino.

Note: the documentation does mention Rhino may run a little slower in certain use cases with .Net Framework.

I’d like to mention that my background is in engineering, not programming. Despite it possibly being a straightforward issue, it had me stumped for a good couple of hours, and I couldn’t find a solution online, this might be an easy error for more seasoned users to fix.

I wanted to share the problem, solution and the steps I took to troubleshoot it, hoping it might save some of you the same headache.

1 Like

Thank you!!! I don’t know how many people this has saved, but today it saved me.

1 Like