System.IndexOutOfRangeException in MessageBinder.DetermineParameters

Dec 12, 2010 at 7:12 AM
Edited Dec 12, 2010 at 7:15 AM

While porting some existing screens to CM, I discovered that I get a System.IndexOutOfRangeException in MessageBinder.DetermineParameters when creating a close button on a view model inheriting from Screen. I have verified that this behavior exists in Change Set a8639bc9322d.

In order to replicate this behavior, create a WPF CM project from the template. Use the following for the view model:

 

using System.ComponentModel.Composition;
using CaliburnMicroCloseButtonExample.Framework;

namespace CaliburnMicroCloseButtonExample
{
    [Export(typeof(IShell))]
    public class ShellViewModel : Screen, IShell
    {
        public void Close() { }
    }
}

 

Use this for the view:

<Grid x:Class="CaliburnMicroCloseButtonExample.ShellView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Background="White">
  
    <Button x:Name="Close">Close</Button>

</Grid>

Dec 12, 2010 at 9:22 AM
Edited Dec 12, 2010 at 9:34 AM

Thanks for pointing it out.

It's an unfortunate side effect of conventions: since you created a "Close" action, CM attempts to find a "CanClose" guard function.
A function with this name does actually exists on Screen, though its signature is not intended to be used as a guard.
I guess this could be solved executing some more congruence check when attempting to find a viable guard (during execution context construction).

I added a ticket for this: http://caliburnmicro.codeplex.com/workitem/64

You can choose, however, a slightly different name or use the default TryClose method (if your method is intended to just close the screen).

Dec 16, 2010 at 1:03 AM

The issue is fixed as of changeset a6b5a421d26c