473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Passing custom exceptions server to client

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
7 4720
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: vbMark | last post by:
Hello, I am doing this: window.location="page2.php?subj="+subj+"&body="+body; to send information to another page. However, I don't want that second page to show up or display in any way....
2
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
1
by: serge calderara | last post by:
dear all, i am a bit confused on the way custom error are handling and occurs. First of all I have understand that customer error is used to defined more user friendly message to my end user and...
3
by: Andy | last post by:
Hi, Have just found a bug in Netscape for some of my Javascript code - works ok in Internet Explorer. Given the following form element: <input type="text" compulsory = "yes" name="an_el"> ...
0
by: Giulio | last post by:
Hi programmers, I'm quite new in this blog, I have a question concerning web services Soap Exceptions: I created a class MySoapException derived from SoapException, I add the references both...
0
by: Giulio | last post by:
Hi programmers, I'm quite new in this blog, I have a question concerning web services Soap Exceptions: I created a class MySoapException derived from SoapException, I add the references both...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.