ViewModelBase Exception

Topics: Issues / bugs
Jul 12, 2012 at 8:03 PM
Edited Jul 12, 2012 at 8:08 PM

Hi Geert,

i have the following situation:

Catel.ViewModelBase <- My.TreeViewViewModelBase { Command Selected { public get; private set; } <- My.XXXXXXViewModel

When one of the My.XXXXXViewModel is closed i get the following exception:

Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The property set method was not found.   
Source : mscorlib
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void SetValue(System.Object, System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
Stack Trace :    bei System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   bei System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   bei Catel.MVVM.ViewModelBase.UnregisterCommands() in c:\Source\Catel\src\Catel.MVVM.NET35\MVVM\ViewModels\ViewModelBase.cs:Zeile 1604.
   bei Catel.MVVM.ViewModelBase.CloseViewModel(Nullable`1 result) in c:\Source\Catel\src\Catel.MVVM.NET35\MVVM\ViewModels\ViewModelBase.cs:Zeile 1877.
   bei Catel.Windows.Controls.MVVMProviders.Logic.UserControlLogic.CloseAndDiposeViewModel(Nullable`1 result) in c:\Source\Catel\src\Catel.MVVM.NET35\Windows\Controls\MVVMProviders\Logic\UserControlLogic.cs:Zeile 508.
   bei Catel.Windows.Controls.MVVMProviders.Logic.UserControlLogic.OnTargetControlUnloaded(Object sender, EventArgs e) in c:\Source\Catel\src\Catel.MVVM.NET35\Windows\Controls\MVVMProviders\Logic\UserControlLogic.cs:Zeile 291.
   bei Catel.Windows.Controls.MVVMProviders.Logic.LogicBase.OnTargetControlUnloadedInternal(Object sender, EventArgs e) in c:\Source\Catel\src\Catel.MVVM.NET35\Windows\Controls\MVVMProviders\Logic\LogicBase.cs:Zeile 388.
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   bei System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   bei System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)
   bei MS.Internal.LoadedOrUnloadedOperation.DoWork()
   bei System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   bei System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   bei System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   bei System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

The exception occurs in Catel.ViewModelBase.UnregisterCommands at the line

propertyInfo.SetValue(thisnullnull);

If i change the Command property setter above to public no exception is thrown

---> Command Selected { public get; PUBLIC set; } <--- this works!

This problem only occurs when i have commands in my viewmodel base class and i derive from it.  Then i must declare all Commands with a public setter instead of a private one....

Could you please take a look at this phenomenon?

Thanks a lot!

Jul 13, 2012 at 11:17 PM

Using Fody? Because that changes calls from regular properties into Catel properties. Maybe we should just ignore the commands.

Jul 14, 2012 at 9:41 AM

Thanks for your tip, but i'm not using Fody.... I think the problem lies somehow in the direction how the UnregisterCommands iterates through the properties...

Could be this the problem? http://stackoverflow.com/questions/10041458/property-set-method-not-found-in-a-derived-type

Jul 18, 2012 at 7:51 AM

That feels strange. We use FlattenHierarchy for reflection and this error never occurred before (and I cannot imagine we never used hierarchy before). I will look into this.