Skip to content

Soft reload throws in deserialization in a common workflow #1250

@benoithudson

Description

@benoithudson

Environment

  • Pythonnet version: current master (with soft reload).

This is in context of Unity Editor.

Details

  1. Use the soft-reload branch of pythonnet within Unity.
  2. Create an asmdef called MyAssembly in Unity.
  3. In the same folder, create a file Foo.cs
namespace Foo
{
  public class Bar
  {
    public static void Quux() { UnityEngine.Debug.Log("quux"); }
  }
}
  1. In the Unity Python console:
import clr
clr.AddReference("MyAssembly")
import Foo
Foo.Bar.Quux()
  1. This will print quux in the Unity console.
  2. In Unity, modify Foo.cs e.g. add a space in it.
  3. Allow Unity to reload the domain.
  4. This works!
  5. In Unity, modify Foo.cs and rename Quux to Quux2.

Expected: Python for .NET is available after reload. Running Python code again will raise AttributeError.

Actual: Python for .NET throws SerializationException: Cannot get the member 'Quux'. I can't even run the Python code again; it fails on import clr. I must restart Unity.

Similarly if I rename the class, the namespace, or the assembly.

The problem appears to be in ManagedType subclasses. These are [Serializable] but they point to things like Type whose deserialization may fail, destroying everything.

I'm working on a proof of concept so that we control the deserialization and we can replace the failed deserialize with a dummy or a null, which only fails if this eventually gets used. I'll post results tomorrow hopefully on a first attempt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions