Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Using Datagrid with LINQ crashes the browser?
4 replies. Latest Post by Yi-Lun Luo - MSFT on April 11, 2008.
(0)
mchlsync
Star
14606 points
2,730 Posts
03-10-2008 10:56 AM |
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?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-12-2008 12:49 AM |
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.
03-12-2008 2:25 AM |
Thanks a lot for your answer. Yi-Lun.
04-01-2008 10:56 AM |
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?
04-11-2008 4:07 AM |
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.