简体   繁体   中英

Fody.PropertyChanged - Could not inject EventInvoker method

I have a ConfigurationViewModel which inherits from BaseViewModel. BaseViewModel is placed in a separate project and has an INotifyPropertyChanged interface implemented. This separate project does not have Fody.PropertyChanged installed.

When I try to build solution I have exception:

Failed to execute weaver C:\Users\Rafal\.nuget\packages\propertychanged.fody\2.6.0\build\..\netclassicweaver\PropertyChanged.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 186
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 109
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Could not inject EventInvoker method on type 'Designer.VVM.ConfigurationViewModel'. It is possible you are inheriting from a base class and have not correctly set 'EventInvokerNames' or you are using a explicit PropertyChanged event and the event field is not visible to this instance. Either correct 'EventInvokerNames' or implement your own EventInvoker on this class. If you want to suppress this place a [DoNotNotifyAttribute] on Designer.VVM.ConfigurationViewModel.
Type:
Fody.WeavingException
StackTrace:
   at ModuleWeaver.InjectMethod(TypeDefinition targetType, InvokerTypes& invokerType)
   at ModuleWeaver.AddOnPropertyChangedMethod(TypeDefinition targetType)
   at ModuleWeaver.FindMethodsForNodes()
   at ModuleWeaver.Execute()
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 182
Source:
PropertyChanged.Fody
TargetSite:
Mono.Cecil.MethodDefinition InjectMethod(Mono.Cecil.TypeDefinition, InvokerTypes ByRef)

When I move BaseViewModel to the same project as ConfigurationViewModel then everything is ok.

Is it standard behaviour? Is it a bug? Am I doing something wrong? How to use Fody.PropertyChanged having BaseViewModel in a separate project?

when the base View Model is in the same project, then the "OnPropertyChanged" method can be injected into that class. When referencing the base View Model from another project, then that project has to have an "OnPropertyChanged" that matches the convention or customise the method name using EventInvokerNames https://github.com/Fody/PropertyChanged/wiki/EventInvokerSelectionInjection

in summary, try adding this to your base view model

public virtual void OnPropertyChanged(string propertyName)
{
    var propertyChanged = PropertyChanged;
    if (propertyChanged != null)
    {
        propertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM