none
System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''HashSet`1' (HashCode=3848023)'.

    Question

  • System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''HashSet`1' (HashCode=3848023)'. BindingExpression:Path=Aspirations[0].Verification.NextVerification; DataItem='VentSystem' (HashCode=28995471); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')


    I have ListBox his ItemSource have Binging to List<VentSystem>

    When I Initial this ItemsSource Data creating in memory, All Very good. Output not write  BindingExpression 

    BUT WHEN I initial ItemSource Data from DataBase I Have this Binding EXEPTION WHY????? I not anderstend HELP MY PLEASS!!


    • Edited by Ahlompys Sunday, February 11, 2018 12:26 PM
    Friday, February 9, 2018 8:09 PM

Answers

  • This Error because Entity Framework creating some diferent type Collection. If load collection like

      foreach (var item in allSV)
                    {
                       var list= context.Class2.Where(d => d.Class2Id == item.Id).ToList();
                        var s = list.GetType();
                        item.Class2= list;
                    }

    All be work



    • Marked as answer by Ahlompys Sunday, February 11, 2018 12:29 PM
    • Edited by Ahlompys Sunday, February 11, 2018 12:32 PM
    Sunday, February 11, 2018 12:29 PM

All replies

  • Hi,

    You did not show us how you got the data from the database.

    Have you checked the type of data returned from the database ? Maybe you should check whether the data(from memory/database) is different.

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, February 10, 2018 4:40 AM
    Moderator
  • Hi,

    Looks like you use EF, Do you allow EF dynamically generated proxy classes which would create type of entity different from actual type. maybe you can disable ProxyCreationEnabled property.

    Please debug your code to check data returned from the database.

    Best Regards,

    Bob 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, February 10, 2018 6:15 AM
    Moderator
  • Hi Ahlompys,

    Please show your debug result to us with some screenshot.

    Check the value of the variable "allSV".

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, February 10, 2018 6:50 AM
    Moderator
  • HI,

    >> Text="{Binding Ventilators[0].Location, Converter={StaticResource LocationEnumToStringConverter}}"

    Do you check DataContext of  the control you're currently bound to?

    Ventilators is the subproperties of a current object?

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, February 10, 2018 7:11 AM
    Moderator
  • Hi,

    Ok, I suggest you upload a demo on OneDrive which can reproduce the problem if possible.

    I can download it and debugging, this will help us quickly analyze your problem.

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, February 10, 2018 7:35 AM
    Moderator
  • I don't see you checking aspirations and that seems to be what your error is from.

    If you bind using an index [0] and there are none, then you'd get that error.

    Using current item is usually more resilient.

    If replace [0] with / where you're indexing aspirations, does the error go away?

    If it doesn't then deep binding directly to your model isn't going to work.

    You'll have to wrap your properties and put some logic in a new property better to cope with bulls and missing items.

    Or translate into a flattened viewmodel with similar logic.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Saturday, February 10, 2018 8:06 PM
    Moderator
  • This Error because Entity Framework creating some diferent type Collection. If load collection like

      foreach (var item in allSV)
                    {
                       var list= context.Class2.Where(d => d.Class2Id == item.Id).ToList();
                        var s = list.GetType();
                        item.Class2= list;
                    }

    All be work



    • Marked as answer by Ahlompys Sunday, February 11, 2018 12:29 PM
    • Edited by Ahlompys Sunday, February 11, 2018 12:32 PM
    Sunday, February 11, 2018 12:29 PM