Strange behavior in release APK

Hi everyone!

I'm experiencing some strange behavior in our release APK. We're using the Nethereum libs to create a key pair and a signed transaction that should be sent to a backend as a ByteStream via Rest. Nothing really fancy. Works like a charm when debugging. On emulator and real device. But as soon as we use the release APK we receive nonsense on the other end.

The App itself works without problems otherwise.

I was able to break it down a little bit. Even a simple constant is encoded wrong in the release APK. Consider the following line:

var gasLimit = 21000.ToBytesForRLPEncoding();

The constant number 21000 is converted into an byte[]. It's sent to the backend with the following line:

httpClient.PostAsync(url, new ByteArrayContent(gasLimit)).Result;

From the debug APK I get "[82, 8]" as a result at the Rest Server. But from the release APK it's "[82, 37, 48, 56, 61]".

Thats the called code out of the Nethereum libs for the encoding:

public static byte[] ToBytesForRLPEncoding(this int number)
        return ToBytesFromNumber(BitConverter.GetBytes(number));

private static byte[] ToBytesFromNumber(byte[] bytes)
        if (BitConverter.IsLittleEndian)
            bytes = bytes.Reverse().ToArray();

        var trimmed = new List<byte>();
        var previousByteWasZero = true;

        for (var i = 0; i < bytes.Length; i++)
            if (previousByteWasZero && bytes[i] == 0)

            previousByteWasZero = false;

        return trimmed.ToArray();

As far as I understand Little Endian values are flipped and leading zeros removed. But nothing that would explain that behavior.

Any thoughts what could go wrong here?


  • BillyLiuBillyLiu Member, Xamarin Team Xamurai


    I have tested your code in the release mode, I can't reproduce your issue.
    Have you tried to use Toast or log to show the value in ToBytesFromNumber()? And have you tested it in other device or emulator?

  • JoachimHJoachimH Member

    @BillyLiu: I get different values via log, too. Tested on emulator and two Android devices.

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai


    I still can't reproduce this issue. Could you share a basic demo that can reproduce the issue through GitHub publicly? So that I can test by my side. Feel free to remove any sensible information.

Sign In or Register to comment.