[Solved] Strange Type or Namespace Error

I got some code from a thread I found from StackOverflow, but it is throwing some strange errors. I’ve tried all the fixes I could find, but they didn’t work.

IReadOnlyList is from the System.Collections.Generic namespace, but its not working for some reason.

Anyone able to shed some light on this issue? The code in question finds permutations for an array.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public static class permutor {

    public static IEnumerable<IEnumerable<T>> GetPermutations<T>(this IEnumerable<T> enumerable)
    {
        var array = enumerable as T[] ?? enumerable.ToArray();

        var factorials = Enumerable.Range(0, array.Length + 1)
            .Select(Factorial)
            .ToArray();

        for (var i = 0L; i < factorials[array.Length]; i++)
        {
            // Error    CS1503    Argument 3: cannot convert from 'long[]' to 'IReadOnlyList<long>' 
            var sequence = GenerateSequence(i, array.Length - 1, factorials);
            // Error    CS1503    Argument 3: cannot convert from 'int[]' to 'IReadOnlyList<int>' 
            yield return GeneratePermutation(array, sequence);
        }
    }

    //Error    CS0246    The type or namespace name 'IReadOnlyList<int>' could not be found (are you missing a using directive or an assembly reference?)

    private static IEnumerable<T> GeneratePermutation<T>(T[] array, IReadOnlyList<int> sequence)
    {
        var clone = (T[])array.Clone();

        for (int i = 0; i < clone.Length - 1; i++)
        {
            Swap(ref clone[i], ref clone[i + sequence[i]]);
        }

        return clone;
    }

    //Error    CS0246    The type or namespace name 'IReadOnlyList<long>' could not be found (are you missing a using directive or an assembly reference?)
    private static int[] GenerateSequence(long number, int size, IReadOnlyList<long> factorials)
    {
        var sequence = new int[size];

        for (var j = 0; j < sequence.Length; j++)
        {
            var facto = factorials[sequence.Length - j];

            sequence[j] = (int)(number / facto);
            number = (int)(number % facto);
        }

        return sequence;
    }

    static void Swap<T>(ref T a, ref T b)
    {
        T temp = a;
        a = b;
        b = temp;
    }

    private static long Factorial(int n)
    {
        long result = n;

        for (int i = 1; i < n; i++)
        {
            result = result * i;
        }

        return result;
    }
}

Have you checked if it is supported by the mono version Unity uses? Couldn’t find what version of .net it was added to on msdn.

My research indicates .NET 4.5.

I just had a look at the object browser and it looks like IReadOnlyList is not on the list under the System.Collections.Generic NameSpace.

The code is beyond my level to play with and I would prefer to keep it the way it is. Is there anyway I can fix this without having to alter the code?

Looks like it was added in .net 4.5, Unity is still on something equivalent of 3.0 if I recall.

I don’t know, you probably need to if You want to use it in Unity. You may get away with just replacing it with a generic List.

Switched IReadOnlyList to IList. Seems to compile with no errors, but I haven’t tested it performance wise, which was the whole point in the first place.

Thanks for your input Thermal.