|
-
Jan 11th, 2008, 02:56 AM
#1
Thread Starter
Junior Member
Public class is not public
I'm trying to serialize some public class, but it doesn't compleate correctly, I receive an error message that class is not public. there is an all code of my console application (from MSDN):
Code:
Imports System.IO
Imports System.Xml.Serialization
Module Module1
Sub Main()
SerializeObject("person.xml") End Sub
Private Sub SerializeObject(ByVal filename As String)
Dim serializer As New XmlSerializer(GetType(OrderedItem))
' Create an instance of the class to be serialized.
Dim i As New OrderedItem()
' Set the public property values.
With i
.ItemName = "Widget"
.Description = "Regular Widget"
.Quantity = 10
.UnitPrice = CDec(2.3)
End With
' Writing the document requires a TextWriter.
Dim writer As New StreamWriter(filename)
' Serialize the object, and close the TextWriter.
serializer.Serialize(writer, i)
writer.Close() End Sub
' This is the class that will be serialized.
Public Class OrderedItem
Public ItemName As String
Public Description As String
Public UnitPrice As Decimal
Public Quantity As Integer End Class
End Module
how can i resolve this issue?
-
Jan 11th, 2008, 02:59 AM
#2
Re: Public class is not public
1) The class cannot be inside a module (I believe)
2) The class hasn't been marked with the Serializable attribute.
3) I'm not 100% sure about this, but I don't know if fields can be serialized, I think (and it's a big think) you have to implement them as actual properties.
-tg
-
Jan 11th, 2008, 03:10 AM
#3
Re: Public class is not public
I can't think of any valid reason to ever declare a class inside a module.
-
Jan 11th, 2008, 03:27 AM
#4
Thread Starter
Junior Member
Re: Public class is not public
1. thank you, you really helped me
2. if you use XML serialization you should not mark class with Serializable attribut.
3. fields can be serialized but it is optionally
-
Jan 11th, 2008, 03:28 AM
#5
Thread Starter
Junior Member
Re: Public class is not public
 Originally Posted by jmcilhinney
I can't think of any valid reason to ever declare a class inside a module.
i didn't know that before
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|