Groups | Blog | Home
all groups > dotnet xml > february 2005 >

dotnet xml : serializable class isn't written to xmlFile


chris yoker via DotNetMonster.com
2/28/2005 6:29:38 PM
hiya,
I have a snipped class as follows:

<code>
<Serializable()> Public Class clsConfigClass
Public Sub New()
End Sub

Private Shared _dbConn As String
Public Shared Property dbConn() As String
Get
Return _dbConn
'Return _dbConn
End Get
Set(ByVal Value As String)
_dbConn = Value
End Set
End Property
End Class
<code>

I am trying to write the property to an xml file with the following code.

<code>

Dim configData As New clsConfigClass
configData.dbConn ="BLAH BLAH"

Serialize("Jim", "myAppConfig.Xml",
Environment.SpecialFolder.ApplicationData, configData)



Public Shared Sub Serialize(ByVal userName As String, ByVal xmlFileName As
String, ByVal folder As Environment.SpecialFolder, ByVal data As Object)

Dim ser As XmlSerializer
ser = New XmlSerializer(data.GetType())
Dim fs As FileStream
fs = New FileStream(GetSettingsPath(userName, xmlFileName ,
folder), FileMode.Create)
Try
ser.Serialize(fs, data)
Finally
fs.Close()
End Try
End Sub
</code>

I don't get any errors, but I don't get it written to my xmlFile either :-(

Assuming that I have successfully written the values to my "clsConfigClass"
property...should this file be successfully written to my XML file?

Any advice / gotchas appreciated :-)

cheers,
yogi

--
chris yoker via DotNetMonster.com
3/1/2005 11:44:28 AM
Hiya, (SOLVED)
the reason it wasn't being serialsied was because the properties were
shared properties, not instance ones.Changing to instance proerties solved
the problem.

cheers,
yogi

--
AddThis Social Bookmark Button