[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Serializable Exception - the constructor won't deserialize.

Phil Jones

8/21/2004 2:17:00 AM

I'm having a problem with Exceptions. If I call my server application from
a client, and the invoked server procedure throws a standard system
[ApplicationException] there is no problem. The client reports accurately
the details of the excpetion.

However, if I have a custom error - for instance:

<Serializable()> Public Class MyException
Inherits Exception
End Class

....and the server procedure throw's this error - the following problem
occurs on the client:

[SerializationException] The constructor to deserialize an object of type
MyException was not found.

Am I missing something with the <Serializable()> attribute? Is there some
other adornment I need to give to the constructor to make it deserialize
correctly?

I'll be trapping these server errors and sending then to the event log - but
as I develop it gets confusing, because I'm not actually seeing the error -
I'm just getting the [Serialization] error.

Thanks everyone!

===
Phil


2 Answers

Sam Santiago

8/21/2004 7:28:00 AM

0

The Exception class implements the ISerializable interface, so I think you need to implement a constructor like the one below. Check out this link and read the bottom:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomseriali...

Here's an excerpt:

"When you derive a new class from one that implements ISerializable, the derived class must implement both the constructor as well as the GetObjectData method if it has variables that need to be serialized.

[Serializable]
public class ObjectTwo : MyObject
{
public int num;

public ObjectTwo() : base()
{
}

protected ObjectTwo(SerializationInfo si, StreamingContext context) : base(si,context)
{
num = si.GetInt32("num"); *** You class might not need to do anything except calling the base class method.
}
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter
=true)]
public override void GetObjectData(SerializationInfo si, StreamingContext context)
{
base.GetObjectData(si,context);
si.AddValue("num", num);
}
}
"

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Phil Jones" <phil_newsgroup@hotmail.com> wrote in message news:OqqjKOyhEHA.556@tk2msftngp13.phx.gbl...
> I'm having a problem with Exceptions. If I call my server application from
> a client, and the invoked server procedure throws a standard system
> [ApplicationException] there is no problem. The client reports accurately
> the details of the excpetion.
>
> However, if I have a custom error - for instance:
>
> <Serializable()> Public Class MyException
> Inherits Exception
> End Class
>
> ...and the server procedure throw's this error - the following problem
> occurs on the client:
>
> [SerializationException] The constructor to deserialize an object of type
> MyException was not found.
>
> Am I missing something with the <Serializable()> attribute? Is there some
> other adornment I need to give to the constructor to make it deserialize
> correctly?
>
> I'll be trapping these server errors and sending then to the event log - but
> as I develop it gets confusing, because I'm not actually seeing the error -
> I'm just getting the [Serialization] error.
>
> Thanks everyone!
>
> ===
> Phil
>
>

Phil Jones

8/21/2004 9:47:00 AM

0

You are a dude with your finger squarly on the serialization pulse!

As always, many thanks for this (stop banging my head on the desk) insight.

===
Phil
(Auckland | Aotearoa)


"Sam Santiago" <ssantiago@n0spam-SoftiTechture.com> wrote in message news:O8QGYB1hEHA.704@TK2MSFTNGP09.phx.gbl...
The Exception class implements the ISerializable interface, so I think you need to implement a constructor like the one below. Check out this link and read the bottom:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomseriali...

Here's an excerpt:

"When you derive a new class from one that implements ISerializable, the derived class must implement both the constructor as well as the GetObjectData method if it has variables that need to be serialized.

[Serializable]
public class ObjectTwo : MyObject
{
public int num;

public ObjectTwo() : base()
{
}

protected ObjectTwo(SerializationInfo si, StreamingContext context) : base(si,context)
{
num = si.GetInt32("num"); *** You class might not need to do anything except calling the base class method.
}
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter
=true)]
public override void GetObjectData(SerializationInfo si, StreamingContext context)
{
base.GetObjectData(si,context);
si.AddValue("num", num);
}
}
"

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Phil Jones" <phil_newsgroup@hotmail.com> wrote in message news:OqqjKOyhEHA.556@tk2msftngp13.phx.gbl...
> I'm having a problem with Exceptions. If I call my server application from
> a client, and the invoked server procedure throws a standard system
> [ApplicationException] there is no problem. The client reports accurately
> the details of the excpetion.
>
> However, if I have a custom error - for instance:
>
> <Serializable()> Public Class MyException
> Inherits Exception
> End Class
>
> ...and the server procedure throw's this error - the following problem
> occurs on the client:
>
> [SerializationException] The constructor to deserialize an object of type
> MyException was not found.
>
> Am I missing something with the <Serializable()> attribute? Is there some
> other adornment I need to give to the constructor to make it deserialize
> correctly?
>
> I'll be trapping these server errors and sending then to the event log - but
> as I develop it gets confusing, because I'm not actually seeing the error -
> I'm just getting the [Serialization] error.
>
> Thanks everyone!
>
> ===
> Phil
>
>