By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

Passing custom exceptions server to client

P: n/a
I have a .net client/server application using remoting, and I cannot get the
custom exception class to pass from the server to the client. The custom
exception is derived from ApplicationException and is defined in an assembly
common to the client and server components. The custom class merely defines
three (3) constructors -- the null constructor; one with a string parameter;
and one with a string and innner exception parameter -- that simply invoke
the base class construcvtor passing any parameters along.

I throw the custom exception in the server, but when the exception is
reported on the client it is a generic
System.Runtime.Remoting.RemotingException! The text indicates that I should
"turn on customErrors in the server's config file", but I do not have a
config file. Right now I do not want to deal with the config files (I have
too many other things to figure out).

The MSDN references the ability to perform configuration programmatically,
but there is no reference to how this customError value can be set that I
can find.

I added a debug statement to my code, and the values returned are False for
local calls and true for remote calls, but I can still find no reference on
how to programmatically enable the passing of the custom exception across
the remote procedure call.

Help!

-Ken
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Ken,

Have you made your exception serializable? If it is not serializable,
then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom
exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that simply invoke
the base class construcvtor passing any parameters along.

I throw the custom exception in the server, but when the exception is
reported on the client it is a generic
System.Runtime.Remoting.RemotingException! The text indicates that I should "turn on customErrors in the server's config file", but I do not have a
config file. Right now I do not want to deal with the config files (I have
too many other things to figure out).

The MSDN references the ability to perform configuration programmatically,
but there is no reference to how this customError value can be set that I
can find.

I added a debug statement to my code, and the values returned are False for local calls and true for remote calls, but I can still find no reference on how to programmatically enable the passing of the custom exception across
the remote procedure call.

Help!

-Ken

Nov 16 '05 #2

P: n/a
I have placed the following decoration at the top of my custom exception
class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Ken,

Have you made your exception serializable? If it is not serializable,
then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
I have a .net client/server application using remoting, and I cannot get

the
custom exception class to pass from the server to the client. The custom
exception is derived from ApplicationException and is defined in an

assembly
common to the client and server components. The custom class merely

defines
three (3) constructors -- the null constructor; one with a string

parameter;
and one with a string and innner exception parameter -- that simply invoke the base class construcvtor passing any parameters along.

I throw the custom exception in the server, but when the exception is
reported on the client it is a generic
System.Runtime.Remoting.RemotingException! The text indicates that I

should
"turn on customErrors in the server's config file", but I do not have a
config file. Right now I do not want to deal with the config files (I have too many other things to figure out).

The MSDN references the ability to perform configuration programmatically, but there is no reference to how this customError value can be set that I can find.

I added a debug statement to my code, and the values returned are False

for
local calls and true for remote calls, but I can still find no reference

on
how to programmatically enable the passing of the custom exception across the remote procedure call.

Help!

-Ken


Nov 16 '05 #3

P: n/a
Ken,

No, that should be it. You don't have any fields of a type not marked
as serializable in your exception, do you?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I have placed the following decoration at the top of my custom exception
class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Ken,

Have you made your exception serializable? If it is not serializable,
then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
I have a .net client/server application using remoting, and I cannot get
the
custom exception class to pass from the server to the client. The
custom exception is derived from ApplicationException and is defined in an assembly
common to the client and server components. The custom class merely

defines
three (3) constructors -- the null constructor; one with a string

parameter;
and one with a string and innner exception parameter -- that simply

invoke the base class construcvtor passing any parameters along.

I throw the custom exception in the server, but when the exception is
reported on the client it is a generic
System.Runtime.Remoting.RemotingException! The text indicates that I

should
"turn on customErrors in the server's config file", but I do not have a config file. Right now I do not want to deal with the config files (I have too many other things to figure out).

The MSDN references the ability to perform configuration programmatically, but there is no reference to how this customError value can be set
that I can find.

I added a debug statement to my code, and the values returned are
False for
local calls and true for remote calls, but I can still find no
reference on
how to programmatically enable the passing of the custom exception

across the remote procedure call.

Help!

-Ken



Nov 16 '05 #4

P: n/a
Below is the definition I am using. As you can see, this is pretty
straight-forward.This definition exists in a common assembly; the server
(remote) code throws an exception of this type and that works (is displayed
in a console window and entered into the Application Event Log), but even
though the client has a Catch for this exception it is not caught!

In the client I Catch a System.Runtime.Remoting.RemotingException that
merely indicates that the "Server encountered an internal error." The
exception foes on to indicate "For more information, turn on customErrors in
the server's .config file." I do not have a config file, and I do not wish
to attempt to begin using one at this stage of the project (deadlines, you
know).

I checked out the customErrors setting in MSDN and it indicates that it
controls whether exception information is marshaled at all. There is even a
reference to a way to check this by invoking
"RemotingConfiguration.CustomErrorsEnabled" -- when I call this with the
parameter True (local), then False is returned; passing False (remote) as
the parameter results in a True return. The explanation is that True
indicates only filtered information is returned and False indicates that
complete information is returned. While I would like False to be returned in
both cases, this appears to be the desired response for remote connections.

Still, I get the generic reoting exception at the client executable rather
than the custom exception. This happens whether I copy the server component
to the server computer and execute it from the command line, or whether I
execute it from inside the IDE in debug mode (I declare the local directory
that contains the debug images as a share and specify the share as the
location of the debug target for the debugger).

Oddly enough, when debugging this on another developer system, things were a
bit different. I was unable to configure the remote debugging facilities
(another issue), so I copied all of the code (release build) local to that
test system and ran both the server and client executables from the same
system. In that case it seemed that the detailed errors from the server
component were being reported back to the client component and being
displayed on the screen!

As I have re-read the MSDN entry on the CustomErrorsEnabled method
repeatedly, it seems I missed on connotation. The return values of
True/False from this method are based on the specific setting of the 'mode'
attibute of the channel -- if this is set to 'remoteOnly' then the results I
am seeing indicate local callers get complete information and remote callers
receive filtered information.

The MSDN entry contains this entry: "The CustomErrorsEnabled method reflects
configuration settings that were either specified in the mode attribute of
the <customErrors> element of the application configuration file or set
programmatically when the server channel was configured. For more
information about configuration options, see Configuration." MSDN has some
references to being able to set configuration programmatically, but I cannot
figure out how to do this from the scant information available. There is no
reference specific to the setting of this 'mode' value for the channel that
I am opening for the connection. There is no exposed property of that name,
and it is not clear how to set this. The only reference is that the config
file should contain something like the following, but there is no reference
that I can find on how to control this setting programmatically -- the only
mechanism seems to be to read a config file!

<configuration>
<system.runtime.remoting>
<customErrors mode="off"/>
</system.runtime.remoting>
</configuration>

//----------------------------------------------------------------
[Serializable()]
public class MyCustomException : ApplicationException
{
public MyCustomException() { }

public MyCustomException(string message) : base(message) { }

public MyCustomException(string message, Exception inner) : base(message,
inner) { }
}
//----------------------------------------------------------------

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uj*************@tk2msftngp13.phx.gbl...
Ken,

No, that should be it. You don't have any fields of a type not marked
as serializable in your exception, do you?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I have placed the following decoration at the top of my custom exception
class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Ken,

Have you made your exception serializable? If it is not serializable, then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
> I have a .net client/server application using remoting, and I cannot get the
> custom exception class to pass from the server to the client. The custom > exception is derived from ApplicationException and is defined in an
assembly
> common to the client and server components. The custom class merely
defines
> three (3) constructors -- the null constructor; one with a string
parameter;
> and one with a string and innner exception parameter -- that simply

invoke
> the base class construcvtor passing any parameters along.
>
> I throw the custom exception in the server, but when the exception is > reported on the client it is a generic
> System.Runtime.Remoting.RemotingException! The text indicates that I
should
> "turn on customErrors in the server's config file", but I do not
have a > config file. Right now I do not want to deal with the config files
(I
have
> too many other things to figure out).
>
> The MSDN references the ability to perform configuration

programmatically,
> but there is no reference to how this customError value can be set

that
I
> can find.
>
> I added a debug statement to my code, and the values returned are

False for
> local calls and true for remote calls, but I can still find no reference on
> how to programmatically enable the passing of the custom exception

across
> the remote procedure call.
>
> Help!
>
> -Ken
>
>



Nov 16 '05 #5

P: n/a
I cresated a file named MyRemoting.config and placed the following text in
that file.

<configuration>
<system.runtime.remoting>
<customErrors mode="off"/>
</system.runtime.remoting>
</configuration>

I then modified modified my code to call the
[RemotingConfiguration.Configure] method before registering my object. Now
when I run the server and client components, the client receives a
System.Runtime.Serialization.SerializationExceptio n -- "The constructor to
deserialize an object of type MyCustomException was not found."

So now it seems that it is transmitting the custom exception, but I am not
receiving it. I shall keep digging.

Is there no way to achieve this without a config file?

-Ken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uj*************@tk2msftngp13.phx.gbl...
Ken,

No, that should be it. You don't have any fields of a type not marked
as serializable in your exception, do you?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I have placed the following decoration at the top of my custom exception
class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Ken,

Have you made your exception serializable? If it is not serializable, then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
> I have a .net client/server application using remoting, and I cannot get the
> custom exception class to pass from the server to the client. The custom > exception is derived from ApplicationException and is defined in an
assembly
> common to the client and server components. The custom class merely
defines
> three (3) constructors -- the null constructor; one with a string
parameter;
> and one with a string and innner exception parameter -- that simply

invoke
> the base class construcvtor passing any parameters along.
>
> I throw the custom exception in the server, but when the exception is > reported on the client it is a generic
> System.Runtime.Remoting.RemotingException! The text indicates that I
should
> "turn on customErrors in the server's config file", but I do not
have a > config file. Right now I do not want to deal with the config files
(I
have
> too many other things to figure out).
>
> The MSDN references the ability to perform configuration

programmatically,
> but there is no reference to how this customError value can be set

that
I
> can find.
>
> I added a debug statement to my code, and the values returned are

False for
> local calls and true for remote calls, but I can still find no reference on
> how to programmatically enable the passing of the custom exception

across
> the remote procedure call.
>
> Help!
>
> -Ken
>
>



Nov 16 '05 #6

P: n/a
OK, so now I have now also changed the exception defintion to

public class MyCustomException : ApplicationException, ISerializable

and also added a public constructor

public MyCustomException(SerializationInfo info, StreamingContext
context) : base(info, context) { }

and I am now receiving my exception at the client!

The problem now (in addition to having this config file I do not want) is
that I cannot catch this exception explicity! In the following code, the
second instance always catches the exception, even though the display
indicates that it is a MyCustomException!

try
{
server.remote_method_call();
}
catch(MyCustomException exc1)
{
MessageBox.Show("MyCustom: " + exc1.ToString());
}
catch(Exception exc2)
{
MessageBox.Show("General Exception: " + exc2.ToString());
}

Argh!

-Ken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uj*************@tk2msftngp13.phx.gbl...
Ken,

No, that should be it. You don't have any fields of a type not marked
as serializable in your exception, do you?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I have placed the following decoration at the top of my custom exception
class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Ken,

Have you made your exception serializable? If it is not serializable, then the framework will not know how to create a representation of the
exception to throw on the client side.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
> I have a .net client/server application using remoting, and I cannot get the
> custom exception class to pass from the server to the client. The custom > exception is derived from ApplicationException and is defined in an
assembly
> common to the client and server components. The custom class merely
defines
> three (3) constructors -- the null constructor; one with a string
parameter;
> and one with a string and innner exception parameter -- that simply

invoke
> the base class construcvtor passing any parameters along.
>
> I throw the custom exception in the server, but when the exception is > reported on the client it is a generic
> System.Runtime.Remoting.RemotingException! The text indicates that I
should
> "turn on customErrors in the server's config file", but I do not
have a > config file. Right now I do not want to deal with the config files
(I
have
> too many other things to figure out).
>
> The MSDN references the ability to perform configuration

programmatically,
> but there is no reference to how this customError value can be set

that
I
> can find.
>
> I added a debug statement to my code, and the values returned are

False for
> local calls and true for remote calls, but I can still find no reference on
> how to programmatically enable the passing of the custom exception

across
> the remote procedure call.
>
> Help!
>
> -Ken
>
>



Nov 16 '05 #7

P: n/a
Actually, it turns out that the 'type' of the exception that is deserialized
at the client is ApplicationException -- the base class of
MyCustomException! How do I convince the constructor to make this a
MyCustomException instance?

-Ken

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
OK, so now I have now also changed the exception defintion to

public class MyCustomException : ApplicationException, ISerializable

and also added a public constructor

public MyCustomException(SerializationInfo info, StreamingContext
context) : base(info, context) { }

and I am now receiving my exception at the client!

The problem now (in addition to having this config file I do not want) is
that I cannot catch this exception explicity! In the following code, the
second instance always catches the exception, even though the display
indicates that it is a MyCustomException!

try
{
server.remote_method_call();
}
catch(MyCustomException exc1)
{
MessageBox.Show("MyCustom: " + exc1.ToString());
}
catch(Exception exc2)
{
MessageBox.Show("General Exception: " + exc2.ToString());
}

Argh!

-Ken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uj*************@tk2msftngp13.phx.gbl...
Ken,

No, that should be it. You don't have any fields of a type not marked
as serializable in your exception, do you?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I have placed the following decoration at the top of my custom exception class. Do I need to do more?

-Ken
[Serializable()]

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
> Ken,
>
> Have you made your exception serializable? If it is not

serializable,
> then the framework will not know how to create a representation of
the > exception to throw on the client side.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "Ken Allen" <ke******@sympatico.ca> wrote in message
> news:ug*************@TK2MSFTNGP09.phx.gbl...
> > I have a .net client/server application using remoting, and I cannot get
> the
> > custom exception class to pass from the server to the client. The

custom
> > exception is derived from ApplicationException and is defined in

an > assembly
> > common to the client and server components. The custom class merely > defines
> > three (3) constructors -- the null constructor; one with a string
> parameter;
> > and one with a string and innner exception parameter -- that simply invoke
> > the base class construcvtor passing any parameters along.
> >
> > I throw the custom exception in the server, but when the exception

is > > reported on the client it is a generic
> > System.Runtime.Remoting.RemotingException! The text indicates that I > should
> > "turn on customErrors in the server's config file", but I do not have
a
> > config file. Right now I do not want to deal with the config files

(I have
> > too many other things to figure out).
> >
> > The MSDN references the ability to perform configuration
programmatically,
> > but there is no reference to how this customError value can be set

that
I
> > can find.
> >
> > I added a debug statement to my code, and the values returned are

False
> for
> > local calls and true for remote calls, but I can still find no

reference
> on
> > how to programmatically enable the passing of the custom exception
across
> > the remote procedure call.
> >
> > Help!
> >
> > -Ken
> >
> >
>
>



Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.