Fody.PropertyChanged-无法注入EventInvoker方法

时间:2019-03-27 14:17:09

标签: fody fody-propertychanged

我有一个ConfigurationViewModel,它继承自BaseViewModel。 BaseViewModel放置在单独的项目中,并实现了INotifyPropertyChanged接口。此单独的项目未安装Fody.PropertyChanged。

当我尝试构建解决方案时,我有一个例外:

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)

当我将BaseViewModel和ConfigurationViewModel移到相同的项目时,一切正常。

这是标准行为吗?是虫子吗?难道我做错了什么?如何在单独的项目中使用具有BaseViewModel的Fody.PropertyChanged?

1 个答案:

答案 0 :(得分:1)

当基本View模型在同一项目中时,可以将“ OnPropertyChanged”方法注入该类中。从另一个项目引用基本View模型时,该项目必须具有一个与约定匹配的“ OnPropertyChanged”或使用EventInvokerNames https://github.com/Fody/PropertyChanged/wiki/EventInvokerSelectionInjection

自定义方法名称。

总而言之,尝试将其添加到基本视图模型中

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