My apologies in advance on this one. I'm a noob to .Net 4, to Linq, to Silverlight, and to Telerik. Most likely this isn't even a Telerik question and is only something I'm not understanding. Can anyone point me in the right direction?
In the following lines, rgvCust is a GridView, and custResult is a list of objects. This code works just fine.
In the following lines, I'm attempting to use Linq on the objects themselves. This fails with the error message pasted below.
{System.MethodAccessException: Attempt by method 'System.Linq.EnumerableQuery.Create(System.Type, System.Collections.IEnumerable)' to access method 'System.Linq.EnumerableQuery`1<System.__Canon>..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)' failed.
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.Linq.EnumerableQuery.Create(Type elementType, IEnumerable sequence)
at System.Linq.Queryable.AsQueryable(IEnumerable source)
at Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source)
at Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection)
at Telerik.Windows.Data.DataItemCollection.CreateCollectionView(IEnumerable source)
at Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source)
at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass49.<Bind>b__48()
at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)
at RadControlsSilverlightApp1.MainPage.btnToggle_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}
Any idea is appreciated! Paul
In the following lines, rgvCust is a GridView, and custResult is a list of objects. This code works just fine.
rgvCust.ItemsSource = null;
rgvCust.AutoGenerateColumns = true;
rgvCust.Columns.Clear();
rgvCust.ItemsSource = custResult;
In the following lines, I'm attempting to use Linq on the objects themselves. This fails with the error message pasted below.
rgvCust.ItemsSource = null;
rgvCust.AutoGenerateColumns = true;
rgvCust.Columns.Clear();
rgvCust.ItemsSource = from x in custResult
orderby x.LastName
select new
{
x.FirstName,
x.LastName,
x.Address,
x.City,
x.State
};
{System.MethodAccessException: Attempt by method 'System.Linq.EnumerableQuery.Create(System.Type, System.Collections.IEnumerable)' to access method 'System.Linq.EnumerableQuery`1<System.__Canon>..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)' failed.
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.Linq.EnumerableQuery.Create(Type elementType, IEnumerable sequence)
at System.Linq.Queryable.AsQueryable(IEnumerable source)
at Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source)
at Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection)
at Telerik.Windows.Data.DataItemCollection.CreateCollectionView(IEnumerable source)
at Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source)
at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass49.<Bind>b__48()
at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)
at RadControlsSilverlightApp1.MainPage.btnToggle_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}
Any idea is appreciated! Paul