I create a .NET Framework SyndicationFeed:
SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
Then I create a new item:
var newItem = new SyndicationItem();
newItem.Id = sourceFeedItem.ItemID;
newItem.Title = new TextSyndicationContent(sourceFeedItem.ItemTitle);
Then I add some iTunes item extensions:
var iTunesExt = newItem.ElementExtensions;
iTunesExt.Add(new XElement("MyElement", "Whatever");
newItem.ElementExtensions.Add(iTunesExt);
Then I add the item to the items list:
List<SyndicationItem> items = new List<SyndicationItem>();
items.Add(newItem);
and set the feed's Items property.
feed.Items = items;
and finally I write the SyndicationFeed feed to an XmlWriter.
feed.SaveAsRss20(xmlWriter);
All goes well if the extensions aren't added, in other words if the newItem.ElementExtensions.Add(iTunesExt); line doesn't execute. But if the line executes, I get the following error upon execution of feed.SaveAsRss20(xmlWriter);.
Type 'System.ServiceModel.Syndication.SyndicationElementExtension' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.
How can I mark iTunesExt with the DataContractAttribute attribute? Or am I misunderstanding it?
Try modifying this to:
That allows you to specify use of the
DataContractSerializer.