Implementing the Terminal API in Unity yields the error. "IndexOutOfRangeException: index was outside the bounds of the array."

We are currently implementing the Terminal API in a Unity (C#) application for the integration part with Square Terminal.
The implementation was done with reference to the “Create terminal checkout” page of the Terminal API documentation.
Execution on the Unity editor is successful, and the Square Terminal screen transitions to a blue screen prompting for payment.
However, when I built the application and checked the operation of the application on an Android device,
The following error occurred and the Square Terminal screen did not transition ”IndexOutOfRangeException: Index was outside the bounds of the array.”
There is no mention of checkout from Android devices in the API Logs on the Developer Dashboard.

Please let me know if there is a solution to this issue, or if there are any settings that need to be made to run on the actual device.
Thank you in advance.

The development environment and implementation code are as follows

Development environment
Development language: C#
Square API version: 26.0.0
Android device version: 7.0, 11.0
Unity2021.3.15f1
Reference page: Create terminal checkout

Implementation code:
var amountMoney = new Money.Builder()
.Amount(10L)
.Currency(“JPY”)
.Build();

var paymentOptions = new PaymentOptions.Builder()
.Autocomplete(null)
.DelayDuration(null)
.AcceptPartialAuthorization(null)
.DelayAction(null)
.Build();

var deviceOptions = new DeviceCheckoutOptions.Builder(deviceId: ”Serial number on the back of the terminal”)
.SkipReceiptScreen(true)
.Build();

var checkout = new TerminalCheckout.Builder(amountMoney: amountMoney, deviceOptions: deviceOptions)
.PaymentOptions(paymentOptions)
.StatementDescriptionIdentifier(null)
.TipMoney(null)
.Build();

var body = new CreateTerminalCheckoutRequest.Builder(idempotencyKey: ”Unique string”, checkout: checkout)
.Build();

try
{
var result = await client.TerminalApi.CreateTerminalCheckoutAsync(body: body);
}
catch (ApiException e)
{
Console.WriteLine(“Failed to make the request”);
Console.WriteLine($“Response Code: {e.ResponseCode}”);
Console.WriteLine($“Exception: {e.Message}”);
Console.WriteLine($“Errors: {e.Errors}”);
Console.WriteLine($“Data: {e.Data}”);
}

That error isn’t a Square error. I searched the error found this on Stack Overflow. :slightly_smiling_face:

The IndexOutOfRangeException is a common exception in C# that occurs when trying to access an array or collection using an index that is outside the valid range. In C#, arrays and collections are zero-based, meaning the index starts from 0 and goes up to the length of the array minus one.

An index is invalid when it’s lower than the collection’s lower bound or greater than or equal to the number of elements it contains. Indexing an empty list will always throw an exception. Use a method like Add to append the item to the end of the list, or Insert to place the item in the middle of the list somewhere, etc. You cannot index into a C# list if that offset doesn’t exist. IndexOutOfRangeException exception is thrown as a result of developer error. Instead of handling the exception, you should diagnose the cause of the error and correct your code.

It’s worth noting that using the appropriate looping constructs, such as for or foreach loops, can help you avoid IndexOutOfRangeExceptions by automatically handling the iteration over the elements within the valid range of the array or collection.