I have some client code calling a method via remoting using the
myProxy = (IProxy)Activator.GetObject(
typeof(IProxy),
"tcp://" + address + ":" + theControllerPort + "/Proxy");
IProxy is defined as
public interface IProxy {
void DoStuff();
}
Proxy is defined as
public class Proxy : MarshalByRefObject, IProxy {
public void DoStuff() {
throw new DerivedException();
}
}
I have an Exception called DerivedException defined as
[Serializable]
public class DerivedException: ApplicationException {
public DerivedException() : base () { }
public DerivedException(string message) : base (message) { }
public DerivedException(string message, Exception innerException) : base (message, innerException) { }
protected DerivedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
When I call myProxy.DoStuff()
try{
result = myProxy.DoStuff();
}
catch (Exception ex) {
myLog.Error("Error", ex);
}
I get an exception:
"Unable to find assembly 'xyz, Version=123, Culture=neutral, PublicKeyToken=null'."
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
...
I would think that my client code should be able to deserialize the thrown DerivedException since DerivedException inherits from Exception and the client code is set up to catch Exception. What am I doing wrong here? If I include the .dll that defines DerivedException in the bin/debug folder of the client code, the exception is received by the client properly. Is there any other way to get this exception to deserialize and be caught properly by the client code?
question from:
https://stackoverflow.com/questions/65911209/throwing-an-exception-on-a-remoting-server-not-defined-in-the-client-causes-an 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…