Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wp7 strange UnhandledException on databinding 0x8000ffff

I am getting a strange unhandled exception during databinding. I am databinding a ListBox with an IList. After populating the list with the objects, I set the DataContext of the ListBox to my object:

IList<Users> users = new List<Users>;
foreach(JToken jresult in Users)
{
User juser = JsonConvert.DeserializeObject<User>(jresult.ToString());
users.Add(juser);

this.DataContext = myObject;

My object has just two fields, name and email:

public class User
{
    public string name { get; set; }
    public string email { get; set; }    }

On the XAML side, I am binding the ListItem and the text blocks within the ItemTemplate as follows:

<ListBox Name="Users" ItemsSource="{Binding}">
<TextBlock Text="{Binding Name}" Name="name" />
<TextBlock Text="{Binding Email}" Name="email" />

During debugging I can see the Users listbox is getting populated with correct items, however after exiting out of the method, the application crashes, and I am taken directly to the App.xaml.cs method Application_UnhandledException. The error details are:

e.ExceptionObject.InnerException
{"0x8000ffff"}
    _data: null
    _HResult: -2146233088
    _innerException: null
    _message: "0x8000ffff"
    _methodDescs: {System.IntPtr[14]}
    _optionalData: null
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233088
    InnerException: Could not evaluate expression
    Message: "0x8000ffff"
    StackTrace: "   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)\r\n   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)\r\n   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)\r\n   at System.Windows.UIElement.Measure(Size availableSize)\r\n   at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(UIElement child, Size layoutSlotSize)\r\n   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImpor
ts.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n"

I have not been able to figure this out, and would really appreciate any guidance, or maybe a better approach for this kind of problem. One article did mention that the ListDictionaryInternal is no longer supported in SilverLight, so I am not sure if that could be the issue, as the error details point to the ListDictionaryInternal.

like image 840
wp7dev Avatar asked Feb 17 '11 11:02

wp7dev


1 Answers

Want to hear something strange. I had this issue, and removed a style="{StaticResource ....} in the XAML and it fixed it. Can someone explain why? I added a local StaticResource right after that and it worked too.

If you have no Styles set anywhere in your ListBox item, then this solution will not help.

like image 195
firebellys Avatar answered Nov 08 '22 18:11

firebellys