6
votes

I'm developing for Windows 8 WinRT framework. The following sample code throws an exception:

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

Is this one more bug in the current WinRT framework (I'm using VS11 and Consumer Preview)? Has someone an idea how to solve this problem?

Btw: I have tested the same code with Windows Phone 7.5 Silverlight and it works without problems...

Thanks for your help.

public class MyListBox : ListBox
{

}

public sealed partial class BlankPage : Page
{
    public BlankPage()
    {
        this.InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var box1 = new ListBox(); 
        box1.ItemsSource = new List<Object> { new Object() }; // works without problems
        Content = box1; 

        var box2 = new MyListBox();
        box2.ItemsSource = new List<Object> { new Object() }; // throws exception
        Content = box2; 
    }
}
1
Ah, COM error reporting is back! - Hans Passant
did you find any workarounds? - notacat
Nope. Waiting for next release (RC) of Win8, at the moment too many bugs... - Rico Suter
Items.Add() and Items.RemoveAt() work with the current version. Unfortunately, I can't wait for the next release - notacat

1 Answers

2
votes

I encountered a similar problem when subclassing ListView. In my case the following approach partially helped: I stopped trying to set ItemsSource of my ListView directly in the code behind but instead I created CollectionViewSource in XAML like:

<UserControl.Resources>
    <CollectionViewSource x:Name="myCollectionViewSource"/>
</UserControl.Resources>
...
...
<ListView
    ...
    ItemsSource="{Binding Source={StaticResource myCollectionViewSource}}" />

And in the code behind I set

this.myCollectionViewSource.Source = new List<Object> { new Object() }; // The real data source respectively

However this seems only to postpone the problem. At least in my case. In my real example I use ObservableVector as the data source. And as soon as any change of ObservableVector collection is performed (for example Clear) I also experience Catastrophic failure (0x8000FFFF). As soon as I use the original ListView (not my subclassed version) all works fine again - exactly as in your case. So my reply cannot be understood as the solution of the problem but maybe it is a hint worth trying. In my case the original assignment works fine, the problems come first after observable collection tries to update. I experimented with ObservableCollection (should work in CP, it did not in DP) but there I faced other problems. It would be interesting to hear whether you was able to make any progress down this road...