473,606 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does Serialization Work On Structures?

Does serialization work on custom data types via structures?

Dim bFormatter As New BinaryFormatter ()
Dim sFile As FileStream = File.Create(Fil ePath)
Dim structure As myStruct
Dim val1 as Integer
Dim Val2 as String
End Structure
Dim aStruct as myStruct

aStruct.val1 = 123
aStruct.val2 = "some text"

bFormatter.Seri alize(sFile, aStruct)
sFile.Close()

Everytime I use serialization on structures I get a PublicKeyToken= null is
not marked as serializable error. I can find much on serialization. Does
the object need some special interface to be serializ-able?
Nov 20 '05 #1
2 10300
Yes it does work. Make sure you marked your structure with the
<Serializable() > attribute. This tells the framework your object/structure
is ok to serialize:
<Serializable() > _
Structure foo
Dim val1 As Integer
Dim Val2 As String
End Structure

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim bFormatter As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim sFile As System.IO.FileS tream = System.IO.File. Create("c:\test ")
Dim x As foo
x.val1 = 123
x.Val2 = "some text"
bFormatter.Seri alize(sFile, x)
sFile.Close()
End Sub

--
Justin Weinberg

Designing a PrintDocument or creating .NET graphics?
Save time with GDI+ Architect.
For more information, visit http://www.mrgsoft.com
"Daryll SHatz" <ds****@cox.net > wrote in message
news:Og******** ******@TK2MSFTN GP12.phx.gbl...
Does serialization work on custom data types via structures?

Dim bFormatter As New BinaryFormatter ()
Dim sFile As FileStream = File.Create(Fil ePath)
Dim structure As myStruct
Dim val1 as Integer
Dim Val2 as String
End Structure
Dim aStruct as myStruct

aStruct.val1 = 123
aStruct.val2 = "some text"

bFormatter.Seri alize(sFile, aStruct)
sFile.Close()

Everytime I use serialization on structures I get a PublicKeyToken= null is
not marked as serializable error. I can find much on serialization. Does
the object need some special interface to be serializ-able?

Nov 20 '05 #2
Daryll,
As Justin stated, you need to mark the Structure as Serializable as he
demonstrated.

Also the following articles covers every thing you wanted to know about
serialization but were afraid to ask:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

Hope this helps
Jay

"Daryll SHatz" <ds****@cox.net > wrote in message
news:Og******** ******@TK2MSFTN GP12.phx.gbl...
Does serialization work on custom data types via structures?

Dim bFormatter As New BinaryFormatter ()
Dim sFile As FileStream = File.Create(Fil ePath)
Dim structure As myStruct
Dim val1 as Integer
Dim Val2 as String
End Structure
Dim aStruct as myStruct

aStruct.val1 = 123
aStruct.val2 = "some text"

bFormatter.Seri alize(sFile, aStruct)
sFile.Close()

Everytime I use serialization on structures I get a PublicKeyToken= null is
not marked as serializable error. I can find much on serialization. Does
the object need some special interface to be serializ-able?

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
824
by: Dave | last post by:
I was curious to know if anyone has suggestions about maintaining various versions of class definitions when using serialization to save data. Is there a "standard" way of handling backward compatibility with previous version file structures? I don't have problems within the program itself, just with loading data from files created with previous versions of the class definition. It seems that if a change as minor as changing a property...
2
3141
by: Todd | last post by:
I've seen others with this same dilema but no solutions. Is there a way to serialize an object containing private fields? What about private fields containing complex data structures such as custom collections of custom objects with private fields? IXmlSerializable? ISerializable?
0
1727
by: Todd | last post by:
What attributes/code do I need to add to a class to get GetObjectData to fire? I need to use XML serialization to serialize an object with private members including complex data structures which eventually may contain other private objects. I can get that method to fire using SOAP serialization, but shouldn't I be able to customize my serialization process using XML serialization? Thanks, Todd.
0
2955
by: uAsking | last post by:
I'm building a client side application that uses webservices. In the client application I'm inheriting from basic types used by the webservices, so the wevservice provides the classes and sets all the serialization attributes for them. The classes are in a very basic structure with a Single object that contains two other objects. I inhert from them and add a function with converts the object returned from the webservice into my object...
2
1432
by: jacob navia | last post by:
I am starting to write a serialization module for structures using XML. This will be along the lines of: http://www.xml.com/lpt/a/1999/09/serialization/index.html Questions: 1) Has anyone worked with this? (Or a similar project) ?
2
5168
by: Phil Da Lick! | last post by:
Hello, Anyone got any good examples of how to serialize a nested class? My outer class has got ArrayList members for inner classes, each with their own data. I need to serialise the lot into an xml file for easy load/save.
10
1394
by: Jesper | last post by:
Hi, I'm writing a program which is, and will continue to be, constantly extended with functionality that require information. Until now the source of this information has been found and modified using notepad in a txt file that was parsed into fields in objects. (This solution because this was the format that an older fortran program was using and we needed to do it in this way in a transition period). Now I would like be able to save...
0
3030
by: ronnotel | last post by:
I have integrated APIs from a third party into my framework. The third party is essentially a .Net wrapper on top of an existing set of C++ classes and structs. I want to pass-around objects in these native structures as much as possible - that is I don't want to fool around with object serialization/deserialization. Data rates approach several hundred thousand objects per second, hence I simply can't pay the performance penalty this...
10
4022
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can anyone please help me with some sample codings and guidance? Can you also suggest some other news group available for socket programming in VB.Net?
0
8016
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7955
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8440
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6773
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5466
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3937
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.