pythonnet icon indicating copy to clipboard operation
pythonnet copied to clipboard

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

Open BadSingleton opened this issue 2 years ago • 0 comments

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

BadSingleton avatar May 29 '23 15:05 BadSingleton