HI,
I have a class that looks like this:
[
Serializable] public class NewsItems : System.Collections.Generic.List<NewsItem>{
};
Any it works just fine for 99% of my needs... Here is the 1% problem, when I want to write out the contents of my collection to XML, I get the following error (pasted below) anyone know how to remedy this
System.InvalidOperationException was unhandled
Message="There was an error reflecting type 'NewsItems'."
Source="System.Xml"
StackTrace:
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel)
at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at Driver.Form1.button1_Click(Object sender, EventArgs e) in E:\eZamiRSS\Driver\Form1.cs:line 34
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Driver.Program.Main() in E:\eZamiRSS\Driver\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Serialize Strong Typed Collection. "There was an error reflecting type.."
Jim Cruis
Starting in .NET 3.0 you can use the DataContractSerializer instead. The DataContractSerializer supports generics and dictionaries. You can find a list of the types supports here: http://msdn2.microsoft.com/en-us/library/ms731923.aspx.
Daniel Roth
Andy Bounsall
SFrench
emmarussell
Yes it is, (see below) unless there is another attrubute I need to add to the methods/fields/properties
One thing I can say is when passed through web service, the newsitems is serialized just fine...
[
Serializable] public class NewsItem{
String publishDate; String originURL; String link; String comments; String title; String description; String feedID; String author; String rawXML; Dictionary<String, String> otherValues;[public get/set properties for each field is only other thing in class]
}
hartinary
Generally that exception includes an inner exception that explains the problem more explicitly
sahan
zippy1981
Quick sanity check, is the NewsItem Serializable
luker
Yes, I only dug down 1 level, and the inner had a inner, which said that the property I have of type Dictionary<String,String> was unserializable!
Thanks