question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error creating Array with Google Sheets

See original GitHub issue

Hi there,

I’m getting an error creating an array. I’ve tried using strings and int dataTypes and I’ve used tabs, comma’s and comma’s with one space to seperate my data in my google sheet but nothing seems to work when I download the sheet.

Here’s the error:

GDataDB Serialization Exception: Value is not a convertible object: System.String to System.String[] ListEntry LocalName: arraytest UnityEngine.Debug:LogError(Object) GDataDB.Impl.Serializer1:Deserialize(ListEntry) (at Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Serializer.cs:71) GDataDB.Impl.Table1:Find(FeedQuery) (at Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Table.cs:99) GDataDB.Impl.Table1:FindAll() (at Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/Table.cs:52) testEditor:Load() (at Assets/Editor/Data/testEditor.cs:67) UnityQuickSheet.BaseGoogleEditor1:OnInspectorGUI() (at Assets/QuickSheet/GDataPlugin/Editor/BaseGoogleEditor.cs:97) testEditor:OnInspectorGUI() (at Assets/Editor/Data/testEditor.cs:35) UnityEditor.DockArea:OnGUI()

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JelleDekkerscommented, Jul 17, 2016

Thanks for replying. Better late than never 😃

Since my last comment I was able to get all types of array working, It’s a bit hacky but it works.

This goes in the Deserialize function in Serializer.cs:

    try
    {
        if (property.PropertyType.IsArray) 
        {
            if (property.PropertyType.GetElementType().IsEnum) 
            {
                var values = c.Value.Split('\n')
                                      .Select(s => s.Replace(" ", string.Empty))
                                      .Select(i => Enum.Parse(property.PropertyType.GetElementType(), i))
                                      .ToArray();

                Array array = (Array)Activator.CreateInstance(property.PropertyType, values.Length);

                // copy the object values to the array
                int l = 0;
                foreach (var value in values) {
                    array.SetValue(value, l++);
                }

                property.SetValue(r, array, null);
            } 
            else {
                object[] temp = c.Value.Split('\n');
                Array array = (Array)Activator.CreateInstance(property.PropertyType, temp.Length);

                for (int i = 0; i < array.Length; i++) {
                    array.SetValue(Convert.ChangeType(temp[i], property.PropertyType.GetElementType()), i);
                }

                property.SetValue(r, array, null);
            }
        } 
        else {
            object value = new object();
            if (property.PropertyType.IsEnum) {
            {
                value = c.Value.Replace(" ", string.Empty);
                value = Enum.Parse(property.PropertyType, value.ToString());
            } 
            else {
                value = ConvertFrom(c.Value, property.PropertyType);
            }

            property.SetValue(r, value, null);
        }
    }
0reactions
kimsamacommented, Aug 9, 2016

merged into master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array Literal Error Combining Queries
When you are using literal arrays, the arrays must have the same number of columns in all aspects of the formula. In your...
Read more >
Error in google spreadsheet with arrays
In google spreadsheet I receive an error and it says, "Array result was not expanded because it would overwrite data in M261".
Read more >
How to solve Error message in Google Sheet array formula
The first thing to try, because is the simplest action, is to remove the blank rows below your data. Another simple option is...
Read more >
How To Create Arrays In Google Sheets
Learn how to create arrays in Google Sheets to take your formula skills to the next level. See how to combine data with...
Read more >
How to Create Arrays in Google Sheets
Here's how you can create them in Google Sheets using arrays. ... formula will return an #ERROR! as it's not valid data in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found