Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Passing byte array to java library

I am creating a binding for a java library and the library needs to be initialized by a byte array. As the java byte range is -128..127 and C# byte range is 0..255 I can't use .net byte array because I can't put negative numbers in the array. I tried changing the parameter type to int[] or to Java.Lang.Byte[] but in that case it throws an exception at runtime because the parameter type is embedded in the const string __id which is used to invoke the java method and changing parameter type causes the java method lookup to fail.

How can I solve this issue ?


  • LeonLuLeonLu Member, Xamarin Team Xamurai

    You can try to use SByte Struct to replace the Byte in C#,

    The SByte value type represents integers with values ranging from negative 128 to positive 127.

    Here is a link about it.

  • GiorgiDGiorgiD USMember ✭✭

    I tried that but it results in this NotSupportedException:

    Don't know how to convert type 'System.SByte' to an Android.Runtime.IJavaObject

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    If it is not supported, you can try to use Stream to replace the Byte to transfer data.

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Are there any updates for this issue? If the reply is helpful, please mark it as an answer, it will help others who have similar issue.

Sign In or Register to comment.