Fody/PropertyChanged

Weaver not running .NET 6 & .NET 7

warent opened this issue · 1 comments

warent commented

You should already be a Patron

I'm not a Patron, sorry, still new to the library and checking it out

Describe the issue

Weavers don't run for a simple project.

Minimal Repro

.NET 6 WpfApp1.zip
.NET 7 WpfApp3.zip

  1. Create a blank WPF Project
  2. Add Fody and PropertyChanged.Fody (Also, obviously add FodyWeavers.xml)
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <PropertyChanged />
</Weavers>
  1. Create a class that implements INotifyPropertyChanged
  2. Create a property such as public int Hello { get; set; }

e.g.

namespace WpfApp1
{
    partial class FileName : INotifyPropertyChanged
    {
        public int Hello { get; set; }
    }
}
  1. Add the class to MainWindow. E.g.
    public partial class MainWindow : Window
    {
        FileName FileName;
        public MainWindow()
        {
            InitializeComponent();
        }
    }
  1. Build

The code generator works (as we can see)

namespace WpfApp1
{
    partial class FileName
    {
        [GeneratedCode("PropertyChanged.Fody", "4.1.0.0")]
        public event PropertyChangedEventHandler? PropertyChanged;

        [GeneratedCode("PropertyChanged.Fody", "4.1.0.0"), DebuggerNonUserCode]
        protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

        [GeneratedCode("PropertyChanged.Fody", "4.1.0.0"), DebuggerNonUserCode]
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs eventArgs)
        {
            PropertyChanged?.Invoke(this, eventArgs);
        }
    }
}

But weaver does not seem to run. FileName.Hello setter and getter are blank, and there is no OnPropertyNameChanged (OnHelloChanged) being created.

Make an effort to fix the bug

I've been researching this for hours but cannot find what would cause this.

warent commented

Realized a combination of issues were happening...

  1. I'm new to C# decompilers. The program I was using was not showing the full decompiled object and hid the getters/setters which were actually there
  2. A second program I'm using to compile a Mono project (Godot) is somehow bypassing Fody's IL Weaving entirely

In other words, Godot was not working with Fody, and when trying with a different non-Godot project to see if Fody was broken, I was using the decompiler incorrectly.

EDIT:
Turns out Godot had a bug which caused it to skip the weaving step.