Skip to main content

Microsoft Silverlight

Answered Question Using Datagrid with LINQ crashes the browser?RSS Feed

(0)

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Using Datagrid with LINQ crashes the browser?

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 L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Using Datagrid with LINQ crashes the browser?

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

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Using Datagrid with LINQ crashes the browser?

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

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Using Datagrid with LINQ crashes the browser?

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 L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Using Datagrid with LINQ crashes the browser?

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.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities