我有一个继承自BaseViewModel的ConfigurationViewModel。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相同的项目中时,一切都很好。
这是标准行为吗?这是个bug吗?我做错了什么吗?如何在单独的项目中使用具有BaseViewModel的Fody.PropertyChanged?
发布于 2019-03-28 07:14:31
当基础视图模型位于同一项目中时,可以将"OnPropertyChanged“方法注入到该类中。当从另一个项目引用基本视图模型时,该项目必须有一个与约定匹配的"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));
}
}https://stackoverflow.com/questions/55379452
复制相似问题