System.Runtime.Remoting.RemotingException: Server encountered an internal error

Just technical sharing. No big deal.

if you ever encountered the following exception.

System.Runtime.Remoting.RemotingException: Server encountered an internal error. For more information, turn off customErrors in the server's .config file.

It is tricky, because it is not telling you what actually is the exception about ?

The first thing you need to do is to follow as what it suggested, turn off customError.

How you do that ?

At the code segment which remoting is being used. Insert the following codes.

RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off

Once this is done, you can see that the exception generated will be different.

The same error, but shown differently.

In this example, you can see that even though the exception message is still 'Server encountered an internal error', however, the stack trace actually shows more meaningful information.

The problem is 'HandleReturnMessage', and it comes from 'get_Var_MyKey'. 'Var_MyKey' is actually a property, which means that it happens while trying to access the value of the property.

This implies two of either one of the followings:
  1. The object which carries the property is already disposed (collected by garbage collector)
  2. In the context of remoting, even if the object is not disposed, it could be however already expired. If this is the case, you must either resort to using local object or implement object leasing and sponsorship. Refer to Client Server Sample (VB.NET) Using Remoting Version 2