Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in Serializing Custom hierarchial Collection
    primarykey
    data
    text
    <p>I had to populate a tree view for which i have made a custom collection<br> Here are the Classes of the custom collection </p> <pre><code>public class EntityBase : ObservableCollection&lt;object&gt; { private string name; public string Name { get { return name; } set { name = value; InvokePropertyChange(this, new PropertyChangedEventArgs("Name")); } } public event PropertyChangedEventHandler PropertyChanged; public void InvokePropertyChange(object sender, PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(sender, e); } } } public class ParentX : EntityBase // Should be the root of my XML { } public class Parent : EntityBase { private ChildC _childC; public ChildC ChildC { get { return _childC; } set { _childC = value; } } } public class ChildA : EntityBase { } public class ChildB : EntityBase { } public class ChildC : EntityBase { private ObservableCollection&lt;ChildB&gt; children = new ObservableCollection&lt;ChildB&gt;(); public ObservableCollection&lt;ChildB&gt; Children { get { return children; } set { children = value; } } } </code></pre> <p>Here is the how i am filling the data in hierarchial order so that a heterogenious tree can be populated... </p> <pre><code>public class DataBase { public ObservableCollection&lt;object&gt; GetData() { ChildB childB1 = new ChildB { Name = "Parent 1 - ChildB 1" }; ChildB childB2 = new ChildB { Name = "Parent 1 - ChildB 2" }; ChildA childA1 = new ChildA { childB1, childB2 }; // ChildA will have ChildB objects as its child childA1.Name = "Parent 1 - ChildA 1"; ChildC childC = new ChildC{Name="CHildC"}; for (int i = 0; i &lt; 5; i++) { childC.Children.Add(new ChildB{Name="Pappu" + i}); // childC children Property will have childB Object } Parent parent1 = new Parent {childC, childA1}; // Parent class will have ChildC and ChildA as its child parent1.Name = "Parent1"; //Family 2 ParentX parentX=new ParentX{Name="Parent"}; parentX.Add(parent1); //ParentX will have Parent as its child return new ObservableCollection&lt;object&gt; { parentX }; } } </code></pre> <p>Here is the serialisation code that i am using..... </p> <pre><code>using (FileStream fileStream=new FileStream(@"D:\text.xml",FileMode.Create)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ParentX), new Type[] { typeof(Parent), typeof(ChildA), typeof(ChildC), typeof(ChildB)}); if (data != null) xmlSerializer.Serialize(fileStream, data); } </code></pre> <p>I am stuck at this ..... It Does not serialize its gives the error.... </p> <pre><code>{"There was an error generating the XML document."} "The type HierarchialTreeView.Model.ChildC may not be used in this context." </code></pre> <p>Plz help I am stuck at this real bad<br> It was difficult to populate a Heterogenious treeView of the required type and now this happened</p> <p>Thanks Ne ways... Community has been very helpful :) </p> <p>Edit :<br> Inner Exception :<br> {"The type HierarchialTreeView.Model.ChildC may not be used in this context."}<br> Inner-inner exception = null<br> There is no more exceptions after this.... (inner inner inner ex)</p> <p>Stack Trace (In case someone needs) :</p> <pre><code>System.InvalidOperationException was unhandled Message=There was an error generating the XML document. Source=System.Xml StackTrace: at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces) at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o) at HierarchialTreeView.MainWindow.Button_Click(Object sender, RoutedEventArgs e) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(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.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at HierarchialTreeView.App.Main() at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.InvalidOperationException Message=The type HierarchialTreeView.Model.ChildC may not be used in this context. Source=System.Xml StackTrace: at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterParentX.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterParentX.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterParentX.Write2_ArrayOfAnyType(Object o) InnerException: </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload