Search code examples
.netexceptionremoting

.NET Remoting Exception in Binary Stream


I faced a strange exception in using .NET remoting, the exception message is as below:

"Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization."

I faced this exception in this code block:

static bool _isUsable=false;

if(_isUsable)
{
    IExchange exchangeObject = (IExchange)Activator.GetObject(typeof(IExchange), "tcp://localhost:24001/ExchangService");
            
    if (exchangeObject != null)
    {
        try
        {
            var result = exchangeObject.GetPrise(20);
        }
        catch (Exception exp)
        {
            var testMessage = exp.Message;
        }
    }
    else
    {
        var testMessage = "object is null";
    }
}

the strange part of this issue is that if I remove the if(_isUsable) block, the .NET remoting is done without an exception.


Solution

  • I used this code block in a DLL which is used in reflection mode, I changed the DLL class to static and this issue was solved.