Serialize System.Management.ManagementBaseObject

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi there.
I want to serialize some WMI classes that generate with one tools of .net framework called "Mgmtclassgen.exe". I tried a lot but nothing Ive gotten.
In this case I try to add property of my class to datatable and then serialize it to XML. I added. For serialization I try this code:
<pre class="prettyprint prettyprinted <span class="pln <span class="typ DataSet<span class="pln ds <span class="pun =<span class="pln <span class="kwd new<span class="pln <span class="typ DataSet<span class="pun ();<span class="pln
ds<span class="pun .<span class="typ Tables<span class="pun .<span class="typ Add<span class="pun (<span class="pln dt<span class="pun );<span class="pln
<span class="kwd string<span class="pln s <span class="pun =<span class="pln dt<span class="pun .<span class="typ DataSet<span class="pun .<span class="typ GetXml<span class="pun ();[/code]
after that I get error with this message:
System.InvalidOperationException was unhandled by user code<br/>
HResult=-2146233079<br/>
Message=System.Management.ManagementBaseObject cannot be serialized because it does not have a parameterless constructor.<br/>
Source=System.Xml<br/>
StackTrace:<br/>
at System.Xml.Serialization.TypeDesc.CheckSupported()<br/>
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)<br/>
at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)<br/>
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)<br/>
at System.Xml.Serialization.XmlSerializerFactory.CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace, String location, Evidence evidence)<br/>
at System.Xml.Serialization.XmlSerializerFactory.CreateSerializer(Type type, XmlRootAttribute root)<br/>
at System.Data.Common.ObjectStorage.GetXmlSerializer(Type type, XmlRootAttribute attribute)<br/>
at System.Data.Common.ObjectStorage.ConvertObjectToXml(Object value, XmlWriter xmlWriter, XmlRootAttribute xmlAttrib)<br/>
at System.Data.XmlDataTreeWriter.XmlDataRowWriter(DataRow row, String encodedTableName)<br/>
at System.Data.XmlDataTreeWriter.Save(XmlWriter xw, Boolean writeSchema)<br/>
at System.Data.DataSet.GetXml()<br/>
at Root.ServiceModel.Appdomaininfo.ToDataTable(Appdomaininfo pAppDomainInfo) in c:UsersOtherDocumentsVisual Studio 2010ProjectsSaminServiceMangementSaminWMIAppDomainInfo.cs:line 1217<br/>
at SaminMangement.WinFrom.FrmEvents.CheckFilteredEvent(String pEventType, ManagementBaseObject pTargetInstance) in c:UsersOtherDocumentsVisual Studio 2010ProjectsSaminServiceMangementWinFormFrmEvents.cs:line 260<br/>
at SaminMangement.WinFrom.FrmEvents.EventArrived(Object sender, EventArrivedEventArgs e) in c:UsersOtherDocumentsVisual Studio 2010ProjectsSaminServiceMangementWinFormFrmEvents.cs:line 222<br/>
InnerException:
This is my question:
How can I serialize this class with System.Management.ManagementBaseObject property and System.Management.ManagementSystemProperties property?

View the full article
 
Back
Top