This is a migrated thread and some comments may be shown as answers.

Serializing a resource dictionary throws an exception

5 Answers 296 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Zoran
Top achievements
Rank 1
Zoran asked on 22 Jan 2015, 12:28 PM
Hello,

I have a trouble Saving a resource dictionary which uses Telerik.Windows.Controls assembly. Telerik.Windows.Controls.

The exception thrown:

An unhandled exception of type 'System.NotSupportedException' occurred in System.dll

Additional information: 'Office2013ResourceKeyTypeConverter' is unable to convert 'Telerik.Windows.Controls.Office2013ResourceKey' to 'System.Windows.Markup.MarkupExtension'.

Part of xaml that's causing the problem:

<Grid>
                <Path
                    Stretch="Fill"
                    Fill="{telerik1:Office2013Resource ResourceKey=ValidationBrush}"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    SnapsToDevicePixels="True"/>
                <Border Background="{telerik1:Office2013Resource ResourceKey=ValidationBrush}" Margin="5 0 0 0" Padding="1">
                    <ContentPresenter
                        Content="{Binding Error}"
                        TextBlock.Foreground="{telerik1:Office2013Resource ResourceKey=MainBrush}"
                        Margin="4 2"
                        TextBlock.FontSize="15"
                         />
                </Border>
            </Grid>
            <ContentControl/>
        </Grid>

and namespace mapping:

xmlns:telerik1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

I load this resource dictionary with

var myDict = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary;

and then try to save it with:

System.Windows.Markup.XamlWriter.Save(myDict);

And that's when the exception is thrown.

Compiler tooltip: "Local property 'ResourceKey' can only be applied to types that are derived from ThemeResourceExtension`1"

I've checked it, and Office2013ResourceExtension derives from ThemeResourceExtension`1.

What might be the problem here?

5 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 26 Jan 2015, 02:57 PM
Hello Zoran,

The exception is caused by the fact that telerik1 namespace does not exis in this style file. In fact Office2013Resource as well as all themes that support mark-up extensions (Windows8, Windows8Touch, Office2013 and VisualStudio2013) reside in telerik namespace. Since we are referencing different assemblies in our controls style files, our xaml preprocessor renames them so that there are no collisions. In your case telerik1 points to Controls assembly and Controls namespace. Please replace telerik1 with telerik or controls (the latter was previously declared as namespace declaration) and everything should work as expected.
As for serializing ResourceDictionary - in fact XamlWriter.Save method has some known limitations stated in msdn documentation. Why do you need to do this with serialization and deserialization? Why don't you create a custom style - do the needed modifications there and apply it implicitly? Do you really need to load and save the whole resource dictionary? Any further information on the topic will help us better understand your scenario and assist you.

Regards,
Evgenia
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Andreas
Top achievements
Rank 1
answered on 15 May 2015, 02:05 PM

Hi!

I also have issues with this. From what I understand, I should change the name somewhere? But what is it that I should change? I have attached a picture of the Telerik.Windows.Controls.xaml. Could you please tell me what I should change, and to what?

 

Thanks in advance.

0
Evgenia
Telerik team
answered on 18 May 2015, 09:25 AM
Hi Andreas,

In your case telerik1 points to Controls assembly and Controls namespace. Please replace telerik1 with telerik (the universal schema) or controls and everything should work as expected. 

 Why we declare telerik and telerik1 in our style files? - Since we are referencing styles from different assemblies in our style files, our xaml preprocessor renames the namespaces so that there are no collisions - it appends 1 after telerik.

We apologize for any inconveniences this may have caused. We will do our best to improve the way our  style files are being preprocessed in future.

Regards,
Evgenia
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Andreas
Top achievements
Rank 1
answered on 19 May 2015, 01:03 PM

Hi!

 

Thanks for the quick response. I removed the telerik1 namespace and changed all references to telerik1 to telerik. But now I get a strange error. See attached image. Is that anything you know of?

0
Evgenia
Telerik team
answered on 21 May 2015, 02:09 PM
Hello Andreas,

We are unaware of such errors in our Telerik.Windows.Controls.Input.xaml implicit style file. Have you made any changes to it except the change of the namespace? Could you please send us a sample runnable version of your project where this reproduces so that we can inspect it locally and further assist you? For the purpose you should open a new support thread and add the sample code there as archive attachment.

Regards,
Evgenia
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Zoran
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or