When I attempt to run the LoadSate method, this line throws an exception:
RadGridViewApplicationSettings
loaded = (RadGridViewApplicationSettings)serializer.ReadObject(stream);
The error message is:
"The type 'System.Windows.DependencyObject' cannot be deserialized because it does not have a public parameterless constructor. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details. Be aware that doing so has certain security implications."
I'm not sure what's causing this.
13 Answers, 1 is accepted
You are quite right and the mentioned exception is thrown indeed. This is due to the optimizations we have included in our Q3 2010 release in the direction of better performance and functionality of the descriptors of RadGridView. We have implemented a temporary solution in the example on this topic in our demo. You may try to work with the most recent version of the RadGridViewSettings class.
Please excuse us for the inconvenience caused so far. We are in the process of improving this functionality. Thank you for your patience and cooperation.
Maya
the Telerik team
I have two buttons which instantiate a new version of the RadGridViewSettings class - one calls the SaveState method, the other calls the LoadState method. I re-arrange columns, add a sort, and hit save. Then I reset them and hit load, but nothing happens. Am I not utilizing the class correctly or am I missing something else?
I am sending you a sample project implementing the requirements you have - saving and loading the state of the RadGridView on clicking of the corresponding button. Please take a look at it and let me know if you need any further assistance on it.
Maya
the Telerik team
The sample project helped me sort out my issue!
I have tried your sample project, but it still gives me issues.
Steps to reproduce:
1) set break point in RadGridViewSettings line 208 (Catch in Save method)
2) Use Filter position Position "Is Equal" DF
3) Save state
In my case exception is "
The type 'System.Windows.DependencyObject' cannot be deserialized because it does not have a public parameterless constructor. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details. Be aware that doing so has certain security implications.
"
yours example gave me "
Type 'SaveAndLoadSettings_SL_Buttons.Position' with data contract name 'Position:http://schemas.datacontract.org/2004/07/SaveAndLoadSettings_SL_Buttons' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
"
The reason for the exception in this case is that the Position enum cannot be deserialized as it is a know type. What you may do is to add it in the types list:
public RadGridViewApplicationSettings(RadGridViewSettings settings)
{
this.settings = settings;
List<
Type
> types = new List<
Type
>();
types.Add(typeof(List<
ColumnSetting
>));
types.Add(typeof(List<
FilterSetting
>));
types.Add(typeof(List<
GroupSetting
>));
types.Add(typeof(List<
SortSetting
>));
types.Add(typeof(Position));
types.Add(typeof(List<
PropertySetting
>));
this.serializer = new DataContractSerializer(typeof(RadGridViewApplicationSettings), types);
}
In case you have more types you may define, you may expose them as a separate list and pass it to the constructor of this class.
Kind regards,
Maya
the Telerik team
thanks for answer,
your answer have helped me in sample project. But not in my application.
Can you try this:
1) http://demos.telerik.com/silverlight/#GridView/SaveLoadSettings
2) In UnitPrice filter click checkbox with value for example 14
3) click in tree view to go to some other grid view feature (i have clicked GridLines Visibility)
4) click back on Save and Load Settings
(Everything works OK till now)
5) now uncheck 14 and type 14 in "Is equal to"
6) click in tree view to go to some other grid view feature (i have clicked GridLines Visibility)
7) click back on Save and Load Settings
(Fillter is not loaded)
and I beleive that there is same exception as in my case ""The type 'System.Windows.DependencyObject' cannot be deserialized ... "
There is suggestion to put
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Runtime.Serialization")]
but i am not sure where?
The fact that the FieldFilters (those you type in) are not saved and loaded is a known issue. We are working on its fix and it will be available as soon as possible. However, the fact that some objects cannot be deserialized is usually due to the fact that their type is not known. May you try to implement the same logic (defining the required types and adding them to the types collection) demonstrated in the sample I attached in your application ? Furthermore, if appropriate, may you try to predefine the sample project so that it fits your requirements and still I am able to see your exact settings ? Or send one of your own ?
Maya
the Telerik team
Hi Maya,
I have example that works ok (if i dont use FieldFilters )
Fact i did not know that it is known bug.
Ill wait for fix.
"The type 'System.Windows.DependencyObject' cannot be deserialized because it does not have a public parameterless constructor. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details. Be aware that doing so has certain security implications."
We had recently upgraded to the newest telerik and had been around 2 years prior to our last update and this is when we saw the error come up. Looks like it was due to changes in the telerik controls when we had updated. The line of code that errors out is
"var theObject = (T)serializer.ReadObject(stream);"
Here is the XML that we are trying to deserialized
.--------------------------------------------------------------------------------------------------------------------------------------------------
<ArrayOfKeyValueOfstringanyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<KeyValueOfstringanyType>
<Key>ColumnSettings</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/EAF.AppBase.Common.ViewModels.Research" i:type="d3p1:ArrayOfRadGridViewSerializer.RadGridViewSettings.ColumnSettings">
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>ACCT_NBR</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>0</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Account Number</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>ACCT_NBR</d3p1:UniqueName>
<d3p1:Width>112</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>ACCT_DSC</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>1</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Account Description</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>ACCT_DSC</d3p1:UniqueName>
<d3p1:Width>202</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>PATTERN_TYPE</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>2</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Pattern Type</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>PATTERN_TYPE</d3p1:UniqueName>
<d3p1:Width>94</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>COMPANY_NBR</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>3</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Company Number</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>COMPANY_NBR</d3p1:UniqueName>
<d3p1:Width>119</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>YEAR_NBR</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>4</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Year</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>YEAR_NBR</d3p1:UniqueName>
<d3p1:Width>53</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>DEPT_NM</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>5</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Department Name</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>DEPT_NM</d3p1:UniqueName>
<d3p1:Width>188</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>RECONCOUNT</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>6</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Recon</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>RECONCOUNT</d3p1:UniqueName>
<d3p1:Width>61</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>REV1_COUNT</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>7</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Review 1</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>REV1_COUNT</d3p1:UniqueName>
<d3p1:Width>76</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
<d3p1:PropertyName>REV2_COUNT</d3p1:PropertyName>
<d3p1:AggregateFunctions />
<d3p1:DataFormatString></d3p1:DataFormatString>
<d3p1:DataType>System.String</d3p1:DataType>
<d3p1:DisplayIndex>8</d3p1:DisplayIndex>
<d3p1:Header xmlns:d5p1="http://www.w3.org/2001/XMLSchema" i:type="d5p1:string">Review 2</d3p1:Header>
<d3p1:IsReadOnly>true</d3p1:IsReadOnly>
<d3p1:IsVisible>true</d3p1:IsVisible>
<d3p1:UniqueName>REV2_COUNT</d3p1:UniqueName>
<d3p1:Width>76</d3p1:Width>
</d3p1:RadGridViewSerializer.RadGridViewSettings.ColumnSettings>
</Value>
</KeyValueOfstringanyType>
<KeyValueOfstringanyType>
<Key>FilterSettings</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/EAF.AppBase.Common.ViewModels.Research" i:type="d3p1:ArrayOfRadGridViewSerializer.RadGridViewSettings.FilterSettings">
<d3p1:RadGridViewSerializer.RadGridViewSettings.FilterSettings>
<d3p1:PropertyName i:nil="true" />
<d3p1:Filter1 xmlns:d5p1="http://schemas.datacontract.org/2004/07/Telerik.Windows.Data" i:nil="true" />
<d3p1:Filter2 xmlns:d5p1="http://schemas.datacontract.org/2004/07/Telerik.Windows.Data" i:nil="true" />
<d3p1:SelectedDistinctValues xmlns:d5p1="http://schemas.datacontract.org/2004/07/Telerik.Windows.Data">
<d5p1:FilterDescriptor>
<d5p1:IsCaseSensitive>false</d5p1:IsCaseSensitive>
<d5p1:Operator>IsEqualTo</d5p1:Operator>
<d5p1:Value xmlns:d7p1="http://www.w3.org/2001/XMLSchema" i:type="d7p1:string">148550</d5p1:Value>
<d5p1:Member>ACCT_NBR</d5p1:Member>
<d5p1:MemberType xmlns:d7p1="http://schemas.datacontract.org/2004/07/System" i:nil="true" />
</d5p1:FilterDescriptor>
</d3p1:SelectedDistinctValues>
</d3p1:RadGridViewSerializer.RadGridViewSettings.FilterSettings>
</Value>
</KeyValueOfstringanyType>
<KeyValueOfstringanyType>
<Key>SortSettings</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/EAF.AppBase.Common.ViewModels.Research" i:type="d3p1:ArrayOfRadGridViewSerializer.RadGridViewSettings.SortSettings" />
</KeyValueOfstringanyType>
<KeyValueOfstringanyType>
<Key>GroupSettings</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/EAF.AppBase.Common.ViewModels.Research" i:type="d3p1:ArrayOfRadGridViewSerializer.RadGridViewSettings.GroupSettings" />
</KeyValueOfstringanyType>
<KeyValueOfstringanyType>
<Key>FrozenColumnCount</Key>
<Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:int">0</Value>
</KeyValueOfstringanyType>
</ArrayOfKeyValueOfstringanyType>
Actually, the recommended way now is to work with RadPersistenceFramework instead. Please check out our demos and documentation for more information.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
gridView.GroupDescriptors.SuspendNotifications(); gridView.GroupDescriptors.Clear();gridView.GroupDescriptors.Add(new ColumnGroupDescriptor() { Column = column, SortDirection = proxy.SortDirection });
gridView.GroupDescriptors.ResumeNotifications();
gridView.FilterDescriptors.SuspendNotifications();
There are many more, but for the most part the same symbols can not be resolved. The version we had upgraded to and are currently using is Silverlight v. 2012.1.326.1050.
Thanks,
Justin
Will it be possible to download our current official release Q3 2012 and test your application with it ? Do you get the same exceptions ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.