Serialize

?

}{

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.
 
G

gigs

}{ said:
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.
look at [Serializable] attribute

to make clas serializable

[Serializable]
public class YourClass
{

}
 
?

}{

gigs said:
}{ said:
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.
look at [Serializable] attribute

to make clas serializable

[Serializable]
public class YourClass
{

}

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
 
I

Ignacio Machin ( .NET/ C# MVP )

}{ said:
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.
look at [Serializable] attribute
to make clas serializable
[Serializable]
public class YourClass
{

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- Hide quoted text -

- Show quoted text -

Use a [NonSerialized] attribute for those members
 
I

Ignacio Machin ( .NET/ C# MVP )

}{ said:
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.

look at [Serializable] attribute

to make clas serializable

[Serializable]
public class YourClass
{



}- Hide quoted text -

- Show quoted text -

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

Ben Voigt [C++ MVP]

Ignacio said:
}{ wrote:
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.
look at [Serializable] attribute
to make clas serializable
[Serializable]
public class YourClass
{

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- Hide quoted text -

- Show quoted text -

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.
 
I

Ignacio Machin ( .NET/ C# MVP )

Ignacio Machin ( .NET/ C# MVP ) wrote:




}{ wrote:
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.
look at [Serializable] attribute
to make clas serializable
[Serializable]
public class YourClass
{
}
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- Hide quoted text -
- Show quoted text -
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.- Hide quoted text -

- Show quoted text -

Hi,

Yes, you are right, in the case that this info is not kept in others
properties or members.
 
A

Arne Vajhøj

Ignacio said:
Ignacio said:
}{ wrote:
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.
look at [Serializable] attribute
to make clas serializable
[Serializable]
public class YourClass
{
}
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.
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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top