How can we serialize a class that is not a custom class of our own?
- by Doug
I need to look at the properties of an object and I cannot instantiate this object in the proper state on my dev machine. I need my client to run some code on her machine, serialize the object in question to disk and then I can analyze the file.
Here is the class I want to serialize.
System.Security.AccessControl.RegistrySecurity
Here is my code:
Private Sub SerializeRegSecurity(ByVal regKey As RegistryKey)
Try
Dim regSecurity As System.Security.AccessControl.RegistrySecurity = regKey.GetAccessControl()
Dim oXS As XmlSerializer = New XmlSerializer(GetType(System.Security.AccessControl.RegistrySecurity))
Dim oStmW As StreamWriter
Dim regDebugFilePath As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "RegDebugFile.xml")
'Serialize object to XML and write it to XML file
oStmW = New StreamWriter(regDebugFilePath)
oXS.Serialize(oStmW, regSecurity)
oStmW.Close()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub
And here's what I end up with in my XML file:
<?xml version="1.0" encoding="utf-8"?>
Any ideas on how to accomplish what I am trying to do? How can we serialize a class that is not a custom class of our own?
Thanks for ANY help. Even an alternate method.