Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

Serialize

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
}{ - 02 Apr 2008 17:52 GMT
I have implemented a class that contains two Serial port objects among other
things. When I try to serialize this class I get an error relating to the
fact that Serial Port class isn't marked as serializable.

Is it possible to accomplish this.

Any help is greatly appreciated.
gigs - 02 Apr 2008 18:03 GMT
> I have implemented a class that contains two Serial port objects among other
> things. When I try to serialize this class I get an error relating to the
[quoted text clipped - 3 lines]
>
> Any help is greatly appreciated.

look at [Serializable] attribute

to make clas serializable

[Serializable]
public class YourClass
{

}
}{ - 02 Apr 2008 18:13 GMT
>> I have implemented a class that contains two Serial port objects among
>> other things. When I try to serialize this class I get an error relating
[quoted text clipped - 12 lines]
>
> }

I did this, but I think the error relates specifically to the fact that my
class contains other classes that aren't serializable. It is only a guess
though because I'm not too familiar with C#.

I will get out my laptop later and post some code and the error received if
it helps.

Thanks
Ignacio Machin ( .NET/ C# MVP ) - 02 Apr 2008 19:10 GMT
> >> I have implemented a class that contains two Serial port objects among
> >> other things. When I try to serialize this class I get an error relating
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Use a [NonSerialized] attribute for those members
Ben Voigt [C++ MVP] - 02 Apr 2008 21:04 GMT
>>>> I have implemented a class that contains two Serial port objects
>>>> among other things. When I try to serialize this class I get an
[quoted text clipped - 26 lines]
>
> Use a [NonSerialized] attribute for those members

I think a custom serialization function is needed, to serialize port number
or whatever needs to be saved, but more importantly to reopen ports when
deserializing.
Ignacio Machin ( .NET/ C# MVP ) - 02 Apr 2008 22:46 GMT
> >> "gigs" <g...@hi.t-com.hr> wrote in message
>
[quoted text clipped - 36 lines]
>
> - Show quoted text -

Hi,

Yes, you are right, in the case that this info is not kept in others
properties or members.
Arne Vajhøj - 05 Apr 2008 20:04 GMT
>>>>>> I have implemented a class that contains two Serial port objects
>>>>>> among other things. When I try to serialize this class I get an
[quoted text clipped - 19 lines]
> Yes, you are right, in the case that this info is not kept in others
> properties or members.

I think the idea in itself are questionable.

There is a reason those fields are not serializable.

On computer A you serialize an instance that has COM1-COM2 and write it
over socket to computer B that has only COM1. What should the receiving
program do ?

Arne
Ignacio Machin ( .NET/ C# MVP ) - 02 Apr 2008 19:36 GMT
> > I have implemented a class that contains two Serial port objects among other
> > things. When I try to serialize this class I get an error relating to the
[quoted text clipped - 15 lines]
>
> - Show quoted text -

The OP problem is that some fields are not serializables, with the
NonSerializable atribute the problem should be solved.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.