pythonnet / pythonnet/pythonnet
Getting an error on python v9.10+ "Cannot create uninitialized instances of types requiring managed activation"
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 780
- PR merge metrics
- No merged PRs in 30d
Description
Environment
- Pythonnet version: 3.0.1
- Python version: 3.11.1
- Operating System: windows
- .NET Runtime: v4.0.30319
Details
- using CLR with 3D app - Solidworks gives me an error:
Unhandled Exception: System.NotSupportedException: Cannot create uninitialized instances of types requiring managed activation.
at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type)
at Python.Runtime.ClassObject.tp_new_impl(BorrowedReference tp, BorrowedReference args, BorrowedReference kw)
at Python.Runtime.NativeCall.Call_3(IntPtr fp, BorrowedReference a1, BorrowedReference a2, BorrowedReference a3)
at Python.Runtime.MetaType.tp_call(BorrowedReference tp, BorrowedReference args, BorrowedReference kw)
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
import clr
clr.AddReference("C:\Program Files\SOLIDWORKS 2019\SOLIDWORKS\SolidWorks.Interop.sldworks.dll")
<System.Reflection.RuntimeAssembly object at 0x00000285677E4900>
from SolidWorks.Interop.sldworks import ISldWorks, SldWorksClass
swApp = ISldWorks(SldWorksClass())
This happening only on python 3.10+
on 3.9 it works well.
update:
The problem is not with the python version, but using VENV.
Outside VENV its working well, but once I setup VENV (any ver) i'm getting the error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SolidWorks interop example with Pythonnet 3.0.1, comparing execution inside and outside a virtual environment. Read the stack trace through Python.Runtime.ClassObject.tp_new_impl and the uninitialized-object creation path. Done means the reported exception is explained and the differing behavior is covered by a reproducible test or documented limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100