DelegateCommand in Prism v4 drop 10 issue

Topics: Prism v4 - WPF 4
Nov 10, 2010 at 9:44 AM

Hello everybody!

I have just upgraded my application (WPF) to drop 10 from the CTP and i am having problems with the DelegateCommand class.

        public DelegateCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod)
            : base((o) => executeMethod((T)o), (o) => canExecuteMethod((T)o))
            if (executeMethod == null || canExecuteMethod == null)
                throw new ArgumentNullException("executeMethod", Resources.DelegateCommandDelegatesCannotBeNull);

            Type genericType = typeof(T);

            // DelegateCommand allows object or Nullable<>.  
            // note: Nullable<> is a struct so we cannot use a class constraint.
            if (genericType.IsValueType)
                if ((!genericType.IsGenericType) || (!typeof(Nullable<>).IsAssignableFrom(genericType.GetGenericTypeDefinition())))
                    throw new InvalidCastException(Resources.DelegateCommandInvalidGenericPayloadType);

When I associate the action with the DelegateCommand and this action has a parameter of type Boolean, DateTime, Int32, etc., then the InvalidCastException is raised.

ShowCalendarCommand = new DelegateCommand<DateTime>(ShowCalendarAction);

private void ShowCalendarAction(DateTime date)

My whole code is full of this kind of Actions (with this type of parameters) and all worked fine until the upgrade, but now i can't continue developing due to this issue.

What is happening? Is there any fix for this problem?

Thanks in advance.


Nov 10, 2010 at 3:18 PM

Hi Anti,

In Prism value types are no longer supported when using DelegateCommand(s). But you could use a Nullable<Decimal>. If you need more information, I think that can find the following forum threads interesting:

Hope this helps.

Fernando Antivero


Nov 10, 2010 at 3:49 PM

Ok, i'm afraid i'll have to change my code, but i understand why value types are no longer allowed.

I'll try your approach in all our classes (about sixty more or less)

Thank you very much!