"Object has been disconnected or does not exist at the server" exception

Viewed 32990

I need to use cross-appdomain calls in my app, and sometimes I have this RemotingException:

Object '/2fa53226_da41_42ba_b185_ec7d9c454712/ygiw+xfegmkhdinj7g2kpkhc_7.rem' has been disconnected or does not exist at the server.

The target object is still alive, I have checked it.

UPD I've set breakpoint in the finalizer of the target object, and it never hits. Thus, this object is alive and wasn't GC'ed.

7 Answers

This happened for us because we had a static variable in one of our classes that was of type AppDomain. The class was used in a long running windows service. AppDomain has a InitializeLifetimeService method that needs to be overridden like this:

public override object InitializeLifetimeService(){
    return null;
}

We were constantly using this as the private variable that loaded and unloaded some dlls for custom built outside logic. The answer has been taken from here: msdn answer

Because we were not able to change this at production time, we ended with a compromise of restarting the windows service at random intervals that are shorter than the lifetime of the static AppDomain variable which by trial and error we found that it is several days.

This question also helped clarify some things about lifetime: stackoverflow-question

in my case, the problem was that in the client computer, there was an virtual network adapter active, disabling the virtual network adapters, the problem was solved

Related