This topic is locked
[SOLVED]

REST View Single Variable already has non array value

6/20/2025 10:25:01 AM
ASPRunner.NET General questions
R
rawales2 author

Struggling with a couple of REST view single record retrievals. The REST api is returning valid JSON in both the list and single record calls. The list page works great. However, when I click on a single record - which passes the url correctly with the record primary key and as I said returns the json correctly, I get the error "Variable already has non array value".

The error points to a line in the XVar.cs class file and the code that creates the array.

Oddly enough, I have another rest view that works perfectly as the list and view page but the Single in the REST isn't even checked so it's not even making the JSON call. So, it appears the single may or may not need to make the api call?

ChatGPT 6/20/2025

The error "Variable already has non array value" suggests that the code is attempting to assign a value to a variable that is expected to be an array, but it already contains a non-array value. This typically occurs when the application is trying to handle the response from the REST API incorrectly.

Here are some steps you can take to troubleshoot and potentially resolve this issue:

  1. Check the API Response: Ensure that the API response for the single record retrieval is returning a valid JSON object that matches what your application expects. The response should be in the correct format, typically a single object rather than an array.


  2. Inspect the Code Handling the Response: Look at the specific code in the ASPRunner.NET project that handles the response for the single record retrieval. It may be expecting an array when it should be handling a single object. You might find this code in the same XVar.cs file or in the controller that processes the API call.


  3. Debugging: Add logging or debugging statements to see what the variable contains before the line of code that throws the error. This will help you understand if the variable is being set correctly or if it's being overwritten somewhere.


  4. Compare with Working Example: Since you mentioned that you have another REST view that works perfectly, compare the configurations and code paths for both the working and non-working examples. Look for differences in how the API calls are made, how responses are processed, and how the data is structured.


  5. Check for Conditional Logic: The single record retrieval may have conditional logic that bypasses the API call under certain circumstances. Ensure that the logic is correctly set up to always call the API when a single record is requested.


  6. Review Configuration: Sometimes, the configuration settings in ASPRunner.NET might affect how the REST API calls are handled. Make sure that the settings for the single record view are correctly configured to align with your API.


  7. Update Your Code: If you find that the code is incorrectly assuming an array structure for the single record response, update it to handle a single object properly.


  8. Consult Documentation or Community: If you're still having trouble, consult the ASPRunner.NET documentation or reach out to community forums for specific guidance related to REST API integration.



By following these steps, you should be able to pinpoint the issue causing the error and implement a solution to properly handle the single record retrieval from your REST API.

R
rawales2 author 6/20/2025

Never mind... the other view that I thought was working for the single is not. I am very confused.

R
rawales2 author 6/23/2025

So, what I learned is that ASP Runner NET expects an array back from a rest api and not just an object for a single so I had to wrap my single api call with brackets. Once I did that it worked.