IndexOutOfRangeException when accessing "Target" on Undo.undoRedoPerformed in Editor

On a custom editor

    OnEnable()
    {
        Undo.undoRedoPerformed += UndoRedoPerformed;
    }


      private void UndoRedoPerformed()
        {
 
            try
            {
                myValue = ((MyClass)target).Property;
            }
            catch (System.IndexOutOfRangeException)
            {
                return;
            }
        }

I need to change stuff on my editor when Undo Redo is performed, update some values. But I cannot access the target.

Even though I get this exception in that exact line inside the try. There is nothing else than this information:

[Exception] IndexOutOfRangeException: Index was outside the bounds of the array.
Editor.get_target() at :0

surprisingly the code inside the Try is executed and “target” contains the target object.
But I try to execute another line after that one, and the second one is not executed. I guess it’s because of the exception.

Is this a bug? How can I access target without having this exception?

Seems like the Target in the Undo callback is not valid anymore due to serialization changes. But if the variable is stored beforehand in the editor (say, in OnEnable), then you can use it to communicate with it.