pythonnet / pythonnet/pythonnet
Calling `len()` or `__len()__` on a System.Array after a domain reload causes Exceptions and/or crashes
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.0/3.0.1
- Python version: 3.10.6
- Operating System: windows 10
- .NET Runtime: mono/Unity, but repros on non-mono too.
Details
Calling len() or __len()__ on an array (like string[]) object after a domain reload results in either a DomainUnloadedException or an AccessViolationException (and sometimes, other types of exceptions). In Unity, this always result in a crash.
I've tried to debug, but couldn't find a solid lead. My hunch is that the slot doesn't get properly set/reset on domain reload.
The example is easier to see with a unit test: https://github.com/Unity-Technologies/pythonnet/tree/array_len_reload
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 with the unit-test reproduction on the array_len_reload branch and exercise len() and __len__() on a System.Array after a domain reload. Trace the array length call through the reload boundary; done means the call no longer raises reload-related exceptions or crashes, including under Unity/Mono.
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