Problem with serialization

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

Hello. I'm getting a serialization error with the following.

I'm doing an app that works with a webservice. The app and the WS has to
work with a class that I made as a DLL; I have some web methods that
receives objects from this class as parameters. Although it compiles, when I
try to add the web reference to the application, I get an error:
"Library.Class cannot be serialized because it does not have a default
public constructor. "

The class has a constructor where I set the attributes, and it's the only
constructor.

Can you please help me?

Regards,

Diego F.
 
All serializable classes have to have a default constructor ie. a
constructor with no parameters. So you need to have a constructor with no
parameters, and your class has to have Serializable attribute. like

[Serializable] // the attrbute
public class Test
{
public Test() // default contructor
{
...
}
}



Fitim Skenderi
 
Thank you for your answer. Now I can compile add the web reference, but I
have another problem :-/ When I'm compiling the application, I get an error
when calling a web method that has an object as a parameter. It expect to
receive an object from the web service type, but I'm passing the object from
my class, as it's the object that must receive.

Why do I have this error?

Regards,

Diego F.


Fitim Skenderi said:
All serializable classes have to have a default constructor ie. a
constructor with no parameters. So you need to have a constructor with no
parameters, and your class has to have Serializable attribute. like

[Serializable] // the attrbute
public class Test
{
public Test() // default contructor
{
...
}
}



Fitim Skenderi

Diego F. said:
Hello. I'm getting a serialization error with the following.

I'm doing an app that works with a webservice. The app and the WS has to
work with a class that I made as a DLL; I have some web methods that
receives objects from this class as parameters. Although it compiles,
when
I
try to add the web reference to the application, I get an error:
"Library.Class cannot be serialized because it does not have a default
public constructor. "

The class has a constructor where I set the attributes, and it's the only
constructor.

Can you please help me?

Regards,

Diego F.
 
Its a problem with your serialization most likely. Try peeking into the
References.cs file and see if you see another type in the definition
that looks exactly like your serializable object, thats most likely the
culprit
Thank you for your answer. Now I can compile add the web reference, but I
have another problem :-/ When I'm compiling the application, I get an error
when calling a web method that has an object as a parameter. It expect to
receive an object from the web service type, but I'm passing the object from
my class, as it's the object that must receive.

Why do I have this error?

Regards,

Diego F.


All serializable classes have to have a default constructor ie. a
constructor with no parameters. So you need to have a constructor with no
parameters, and your class has to have Serializable attribute. like

[Serializable] // the attrbute
public class Test
{
public Test() // default contructor
{
...
}
}



Fitim Skenderi

Hello. I'm getting a serialization error with the following.

I'm doing an app that works with a webservice. The app and the WS has to
work with a class that I made as a DLL; I have some web methods that
receives objects from this class as parameters. Although it compiles,
when
I

try to add the web reference to the application, I get an error:
"Library.Class cannot be serialized because it does not have a default
public constructor. "

The class has a constructor where I set the attributes, and it's the
only
constructor.

Can you please help me?

Regards,

Diego F.
 
Back
Top