Fody.PropertyChanged - 无法注入 EventInvoker 方法
Fody.PropertyChanged - Could not inject EventInvoker method
我有一个继承自 BaseViewModel 的 ConfigurationViewModel。 BaseViewModel 放在一个单独的项目中,并实现了 INotifyPropertyChanged 接口。这个单独的项目没有安装 Fody.PropertyChanged。
当我尝试构建解决方案时出现异常:
Failed to execute weaver C:\Users\Rafal\.nuget\packages\propertychanged.fody.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 相同的项目时,一切正常。
这是标准行为吗?这是一个错误吗?难道我做错了什么?如何在单独的项目中使用 Fody.PropertyChanged 拥有 BaseViewModel?
当基础视图模型在同一个项目中时,"OnPropertyChanged" 方法可以注入到那个 class 中。从另一个项目引用基本视图模型时,该项目必须有一个符合约定的 "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));
}
}
我有一个继承自 BaseViewModel 的 ConfigurationViewModel。 BaseViewModel 放在一个单独的项目中,并实现了 INotifyPropertyChanged 接口。这个单独的项目没有安装 Fody.PropertyChanged。
当我尝试构建解决方案时出现异常:
Failed to execute weaver C:\Users\Rafal\.nuget\packages\propertychanged.fody.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 相同的项目时,一切正常。
这是标准行为吗?这是一个错误吗?难道我做错了什么?如何在单独的项目中使用 Fody.PropertyChanged 拥有 BaseViewModel?
当基础视图模型在同一个项目中时,"OnPropertyChanged" 方法可以注入到那个 class 中。从另一个项目引用基本视图模型时,该项目必须有一个符合约定的 "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));
}
}