Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Using Datagrid with LINQ crashes the browser? RSS

4 replies

Last post Apr 11, 2008 08:07 AM by Yi-Lun Luo - MSFT

(0)
  • mchlSync

    mchlSync

    Star

    14968 Points

    2799 Posts

    Using Datagrid with LINQ crashes the browser?

    Mar 10, 2008 02:56 PM | LINK

    Hello,

    I'm having some problems in using DataGrid with LINQ. 

    The following code makes crashing the IE7. 

                         XDocument xmlProducts = XDocument.Parse(xmlContent);

                        var products = from product in xmlProducts.Descendants("Product")
                                       select new
                                       {
                                           ProductID = Convert.ToInt32(product.Element("ProductId").Value),
                                           ProductName = (string)product.Element("ProductName").Value
                                       };

                        datagrid1.ItemsSource = products;

    Env:

    1) Vista Home Premium (32)
    2) VS 2008  + SL2 (beta1)
    3) IE7

    Let me know if you need more details.  

    Note:

    If you are using class and List<T> like the example from doc, it's working fine. but why not work with LINQ and implicitly-typed variable?

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net
  • Yi-Lun Luo - MSFT

    Yi-Lun Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: Using Datagrid with LINQ crashes the browser?

    Mar 12, 2008 04:49 AM | LINK

    Hello, actually the problem is: Anonymous Types are internal. Currently data binding doesn't support binding to non-public classes. Try to use a ListBox to bind to an internal class, you'll find a similar problem.

    The root cause seems to be: Data binding uses reflection, and reflection needs high security permissions. Silverlight runs in a sand box, where such security permissions are not granted.

    shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
  • mchlSync

    mchlSync

    Star

    14968 Points

    2799 Posts

    Re: Using Datagrid with LINQ crashes the browser?

    Mar 12, 2008 06:25 AM | LINK

    Thanks a lot for your answer. Yi-Lun.  

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net
  • mchlSync

    mchlSync

    Star

    14968 Points

    2799 Posts

    Re: Using Datagrid with LINQ crashes the browser?

    Apr 01, 2008 02:56 PM | LINK

    Yi-Lun Luo - MSFT

    Try to use a ListBox to bind to an internal class, you'll find a similar problem.
     

    Hello Yi-lun,

    I just tired to use ListBox instead of Datagrid. it's working fine. Could you please review this issue?  

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net
  • Yi-Lun Luo - MSFT

    Yi-Lun Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: Using Datagrid with LINQ crashes the browser?

    Apr 11, 2008 08:07 AM | LINK

    Hi Michael, sorry for the late response. But I really don't see how you get it to work with ListBox. This is a known bug. swildermuth (The ADO Guy) already reported this issue on a ListBox from the Jolt private connect. Any ItemsControl bound to internal types will cause this problem. While data binding to internal types such as anonymous types are not supported, we understand we should not hang the browser. Our developers are investigating this issue.

    shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.