Prevent crash during debugging when attempting to inspect PyObject by lostmsu · Pull Request #1483 · pythonnet/pythonnet

What does this implement/fix? Explain your changes.

When debugging code, that uses PyObject instances, debugger would try to execute PyObject.ToString to show PyObject values in watches window. That call causes AccessViolationException when the current thread does not hold global interpreter lock.

This change adds DebuggerDisplay attribute to PyObject, that makes debugger first check if GIL is held by the current thread, and only use ToString when it does. Otherwise, a message with object handle and a suggestion to acquire GIL is displayed.