pythonnet / pythonnet/pythonnet

Calling `len()` or `__len()__` on a System.Array after a domain reload causes Exceptions and/or crashes

Open
#2,171 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.