Nethereum: Decoding Struct from View Function: Value was either too large or too small for an Int32

Hello! I’m working in C# with Unity and there’s this struct that I expect to get back:

[FunctionOutput]
public class SubmissionDataDTO : IFunctionOutputDTO
        {
            [Parameter("address", "tournament", 1)]
            public string TournamentAddress { get; set; }
            [Parameter("uint256", "roundIndex", 2)]
            public BigInteger RoundIndex { get; set; }
            [Parameter("bytes32", "commitHash", 3)]
            public string CommitHash { get; set; }
            [Parameter("string", "content", 4)]
            public string ContentHash { get; set; }
            [Parameter("uint256", "reward", 5)]
            public BigInteger Reward { get; set; }
            [Parameter("uint256", "timestamp", 6)]
            public BigInteger Timestamp { get; set; }
        }

But Nethereum is telling me after making a call to:

public static IEnumerator getSubmission(string submissionHash)
        {
            var queryRequest = new QueryUnityRequest<GetSubmissionFunction, MatryxSubmission.SubmissionDataDTO>(NetworkSettings.infuraProvider, NetworkSettings.activeAccount);
            yield return queryRequest.Query(new GetSubmissionFunction() { SubmissionHash = Utils.HexStringToByteArray(submissionHash) }, address);
            yield return queryRequest.Result;
        }

that:

OverflowException: Value was either too large or too small for an Int32. System.Numerics.BigInteger.op_Explicit (System.Numerics.BigInteger value) (at <54fb6b36b4f84da49924d0eaf4d45806>:0) Nethereum.ABI.Decoders.IntTypeDecoder.DecodeInt (System.Byte[] encoded) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.EncoderDecoderHelpers.GetNumberOfBytes (System.Byte[] encoded) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeOutput (System.Byte[] outputBytes, Nethereum.ABI.FunctionEncoding.ParameterOutput[] outputParameters) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes (System.Byte[] output, System.Object result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes (System.String output, System.Object result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes[T] (System.String output, T result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.FunctionCallDecoder.DecodeFunctionOutput[T] (T functionOutputResult, System.String output) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.Contracts.FunctionOuputDTOExtensions.DecodeOutput[TFunctionOutputDTO] (TFunctionOutputDTO functionOuputDTO, System.String output) (at <674e307a3d034490917846d11c4e497c>:0) Nethereum.JsonRpc.UnityClient.QueryUnityRequest`2+<Query>d__7[TFunctionMessage,TResponse].MoveNext () (at <5188d924381348829350a9b1de03c968>:0) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

And that confuses me because I’m using BigIntegers. Additionally, if I change the first BigInteger field of SubmissionDataDTO (“roundIndex”) to type long in the struct, I get a different error:

OverflowException: Value was either too large or too small for an Int64. System.Numerics.BigInteger.op_Explicit (System.Numerics.BigInteger value) (at <54fb6b36b4f84da49924d0eaf4d45806>:0) Nethereum.ABI.Decoders.IntTypeDecoder.DecodeLong (System.Byte[] encoded) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.Decoders.IntTypeDecoder.Decode (System.Byte[] encoded, System.Type type) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.ABIType.Decode (System.Byte[] encoded, System.Type type) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeOutput (System.Byte[] outputBytes, Nethereum.ABI.FunctionEncoding.ParameterOutput[] outputParameters) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes (System.Byte[] output, System.Object result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes (System.String output, System.Object result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeAttributes[T] (System.String output, T result, System.Reflection.PropertyInfo[] properties) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.ABI.FunctionEncoding.FunctionCallDecoder.DecodeFunctionOutput[T] (T functionOutputResult, System.String output) (at <8f2bfa5f1f89424d8aca5929566474f6>:0) Nethereum.Contracts.FunctionOuputDTOExtensions.DecodeOutput[TFunctionOutputDTO] (TFunctionOutputDTO functionOuputDTO, System.String output) (at <674e307a3d034490917846d11c4e497c>:0) Nethereum.JsonRpc.UnityClient.QueryUnityRequest`2+<Query>d__7[TFunctionMessage,TResponse].MoveNext () (at <5188d924381348829350a9b1de03c968>:0) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

A ping to our server reveals that the timestamp of the Submission is 1553628157, which BigInteger.Parse() seems to have no problem with… Halp!

To reproduce:

  1. Clone/download the Calcflow repo from the Matryx_Amendment branch
  2. Run Calcflow/Assets/_Scenes/FreeParameterization.unity from Unity 2018.2. The error should pop up in the console after grabbing ABIs and things from our server.

Environment: Windows 10 Home Nethereum 3.2.0 (net461dllsAOT.zip) Unity 2018.2

I would suggest a solution but I don’t know what’s happening! 😦

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

I have a similar problem with .NET Core 5 using Code Generation. Nethereum.Autogen.ContractApi Version 4.11.0 Nethereum.Web3 Version 4.14.0 solidity compiler version is 0.8.20 I have no enum, Just the following simple contract:

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

contract SimpleStorage {
    struct Person {
        uint256 age;
        string name;
    }
    Person[] public people; //dynamic array (size)

    function addPerson(string memory _name, uint256 _age) public {
        people.push(Person(_age, _name));
        getAgeByName[_name] = _age;
    }

    mapping(string => uint256) public getAgeByName;

    function getAge(string memory _name) public view returns (uint256) {
        return getAgeByName[_name];
    }
}

Error: System.OverflowException: Value was either too large or too small for a Decimal. at System.Number.ThrowOverflowException(TypeCode type) at System.Decimal.DecCalc.VarDecFromR8(Double input, DecCalc& result) at System.Convert.ToDecimal(Double value) at Nethereum.Util.BigDecimal.op_Implicit(Double value) at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestBaseFee(BigInteger[] baseFee, Int32[] order, Int32 timeFactor) at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFees(FeeHistoryResult feeHistory, BigInteger tip) at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeesAsync() at Nethereum.RPC.Fee1559Suggestions.TimePreferenceFeeSuggestionStrategy.SuggestFeeAsync(Nullable1 maxPriorityFeePerGas) at Nethereum.RPC.TransactionManagers.TransactionManagerBase.SetTransactionFeesOrPricingAsync(TransactionInput transaction) at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignTransactionRetrievingNextNonceAsync(TransactionInput transaction) at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput transaction) at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SendTransactionAsync(TransactionInput transactionInput) at Nethereum.Contracts.DeploymentHandlers.DeploymentTransactionSenderHandler1.SendTransactionAsync(TContractDeploymentMessage deploymentMessage) at Nethereum.Contracts.DeploymentHandlers.DeploymentTransactionReceiptPollHandler`1.SendTransactionAsync(TContractDeploymentMessage deploymentMessage, CancellationToken cancellationToken) at Solidity.Controllers.SolidityController.DeployContract(Web3 web, SimpleStorageDeployment deployment) in E:\Projects\Solidity\Solidity\Solidity\Controllers\SolidityController.cs:line 43 at Solidity.Controllers.SolidityController.Deploy() in E:\Projects\Solidity\Solidity\Solidity\Controllers\SolidityController.cs:line 26

Any tip on how to fix this ?