NET Remoting Exception not handled Client-Side?

First and foremost do not inherit from ApplicationException This advice has been around for a while, and I believe FxCop will automatically generate a message around this Next, you should usually decorate your custom exception with the Serializable attribute. I think this is your main issue, as I get an exception on the method call saying AuthenticationException is not marked as serializable.

First and foremost, do not inherit from ApplicationException. This advice has been around for a while, and I believe FxCop will automatically generate a message around this. Next, you should usually decorate your custom exception with the Serializable attribute.

I think this is your main issue, as I get an exception on the method call saying AuthenticationException is not marked as serializable.

1 Ah, yes. Here is FxCop's message: warning : CA1058 : Microsoft. Design : Change the base type of 'AuthenticationException' so that it no longer extends 'ApplicationException'.

This base exception type does not provide any additional value for framework classes. Extend 'System. Exception' or an existing unsealed exception type instead.Do not create a new exception base type unless there is specific value in enabling the creation of a catch handler for an entire class of exceptions.

– Jesse C. Slicer Sep 30 '09 at 17:08 Ah. I'm sorry.

I forgot to include that line when copying my class. I did decorate my exception with Serializable. – Daniel Joseph Sep 30 '09 at 17:59 I'm reading your comment above to Joe regarding not having the exception caught on the client side.

I have whipped together a quick Remoting server and client harness and it's getting caught client-side each and every time and NOT on the server. I'll ask a couple more qualifying questions to hopefully guide us toward the solution to this mystery. #1: Is the class which holds MyEquals descended from MarshalByRefObject?

If not, it should be so that it will be marshalled over Remoting correctly. #2: How are you hosting the server? IIS, a Windows Service or just a stand-alone app to test?

– Jesse C. Slicer Sep 30 '09 at 18:57 Answers to your questions (Thanks for being patient by-the-way and even whipping up a test app) #1: Yes, MyEquals is in a class that descends from MarshalByRefObject.It is the grandchild of that object, but I'm guessing that wouldn't cause the problem. #2: I am using a standalone test application.

However, this console app constructs the remoted object inside of another dll assembly, so the remoted object can be bound to a Windows Service at a later time. – Daniel Joseph Sep 30 '09 at 19:46 Additionally, I built a test app myself, and I have the same issue. On the server side, I have a method that throws CustomException.

"throw new CustomException();" following that class model above. I still get the same error "CustomException was unhandled by user code" on the server and nothing on the client. – Daniel Joseph Sep 30 '09 at 19:48.

Try catch(Exception) on the client side, and inspect the type of the exception being caught as well as any inner exceptions. It might give some clues. Some other remarks: ApplicationException is deprecated.

You should normally derive from System.Exception. I normally add the Serializable attribute to custom exceptions. Not sure if this is important.

You should normally override System.Exception. GetObjectData rather than explicitly implementing ISerializable.GetObjectData. In your case you're not serializing any additional data, so I would neither override it nor explicitly implement it.

Again I'm unsure if this would have any impact. My template for a serializable custom exception looks like the following, and I haven't had any problems with serialization over a remoting connection. Serializable public class CustomException : Exception { /// /// Initializes a new instance of the class.

/// public CustomException() { } /// /// Initializes a new instance of the class with /// a specified error message. /// public CustomException(string message) : base(message) { } /// /// Initializes a new instance of the class with /// a specified error message and a reference to the inner exception that is a cause /// of this exception. /// public CustomException(string message, Exception inner) : base(message, inner) { } /// /// Initializes a new instance of the class with /// serialized data.

/// protected CustomException(SerializationInfo info, StreamingContext context) : base(info, context) { } } UPDATE Also if you're hosting the server code in IIS, you need the following in web. Config to allow exceptions to propagate to the client: ... ...

I implemented my AuthenticationException per your custom exception template. The exception was still NEVER caught on the client side. The server halted with "AuthenticationException was unhandled by user code" Do I have to specify to the server application that there is a client willing and waiting to handle any exceptions that are thrown?

– Daniel Joseph Sep 30 '09 at 18:08 "Do I have to specify to the server application ..." - see update above – Joe Sep 30 '09 at 20:29.

There are different reasons for this error, and you guys have mentioned more than a couple. I have noticed another reason for this error; and that's when the constructor of the remotable object being called remotely throws and exception. The exceptions are not being serialized because the object itself wasn't initialized at that point.

I believe you should avoid ANY code that might cause a custom exception to be thrown inside the remotable object's constructor. And if a system exception was thrown during the execution of the code inside the constructor, you should deal with it as a system error (unknown) and build a mechanism to store the details of that exception using the file system or whatever. .

Net remoting sounded really appealing back in the days, but the larger your project gets, and the more concepts you introduce to your code, the more weaknesses this technology reveals. It's a good technology, but you need lots of experience to make a robust solution out of it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions