Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
System.OverflowException when calling ByteArray.AsDelphiArray

I am transferring byte arrays from .Net to Delphi. This operation is repeated thousands of times and the length of the byte array is beteeen 5k and 500k. The operations runs without issues for a couple of minutes but then crashes on the .Net side with the following error:

  Message=Arithmetic operation resulted in an overflow.
  at Atozed.CrossTalk.Right.CTStreamReader.Read() in Atozed.CrossTalk.Right\CTStreamReader.cs:line 67

  This exception was originally thrown at this call stack:
    Atozed.CrossTalk.Right.CTStreamReader.Read() in CTStreamReader.cs

On the Delphi side I am using ByteArray.AsDelphiArray to get the bytes. The exception is happening when this method is called.

If I take the same byte array which causes this and transfer it in isolation (e.g. without making any other transfers beforehand) then everything works fine. So the error is caused by repeating the operation many times with different arrays.
I have already tried to use CopyToDelphiArray instead but it yields the same error.
I have also added a logic which catches this error and reverts to use a for loop to get the bytes from the ByteArray by index. This works but unacceptable slow. Note that once the exception was thrown AsDelphiArray only works for a couple of calls and then the same exception is thrown.

Messages In This Thread
System.OverflowException when calling ByteArray.AsDelphiArray - by gezaszabo - 12-25-2021, 10:53 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)