Invalid Stream Length

I have a RO svc created in D2007 that is being consumed by a .NET tool. We are getting an invalid stream length error returned on a call to the server. Both ends are using version X.861.

Typically I’ve seen this caused by the wrong RODL file–but I’ve triple checked it and it and the .NET service is using the correct one.

We are using binary messages.

In doing some analysis, we see that the stream length is being read from the wrong part of the binary stream. The .NET programmer converted the sting length to hexadecimal and with a packet sniffer saw that it is off by 4 bytes.

Any ideas what might be causing this? Anything we might look at? I’ve had 2 programmers on this for a day now and we can not find a solution.

Thank you,

Ed Dressel

We found the problem: .NET writes a variant Boolean as a byte (VariantHelpers.cs):

                case VariantCodes.varBoolean:
                    aSerializer.WriteByte((Boolean)aVariant ? (Byte)1 : (Byte)0);
                    break;

Delphi reads it as an integer (uROStreamSerializer.pas)

varBoolean:begin 
  fStream.ReadBuffer(lByteValue, SizeOf(integer)); 
  Variant(Ref) := (lByteValue <> 0);
end;

Delphi also writes an integer for byte (and guess that .NET reads a byte).

I can change the Delphi source, or I could change the .NET source (as a primary Delphi shop, I would prefer the latter), but I don’t want to change it it different than what might be in the next time I update).

Ed Dressel

Thanks, logged as bugs://53019 for review
Posted by Bugs for Mac

Hello Ed,

Looks like your RO/.NET version is outdated a bit. This problem was fixed in the middle of 2011 and the fix was introduced with the Sep 11 release.
Because Variant is a Delphi type and used primarily by Delphi users we have changed the .NET code and now it looks like:

switch (lTypeCode)
{
  case VariantCodes.Boolean:
    serializer.WriteInt32((Boolean)value ? (Int32)1 : (Int32)0);
    break;

and

switch ((VariantCodes)lTypeCode)
{
  case VariantCodes.Boolean:
    // Because of bug described in #48011 we must read Int32 but only LSB is meaningful
    return (serializer.ReadInt32() & 0xff) != 0;

Best regards - Sergey