Hello all,
I am getting the following run-time error every time I try to run a program I've converted from Lisp to C#:
System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Single[]' to type 'System.Collections.Generic.List`1[System.Single]'."
In the function below the problem is occurring at line 16. The datatypes are all correct and verified elsewhere, so it is not a problem of the mismatched types in the that sense. However, it appears that C# does not allow you to cast an object to a list... I hope that isn't the case, especially since that would mean me rewriting hundreds of lines of code.
Here are portions of the code where I am receiving errors:
public static List<List<int>> run_neural_net()
{
initialize_network(5, 5);
initialize_the_network();
learn_the_patterns(50);
List<int> learnedCats_second = new List<int>();
for (int i = 0; i < learned_categories.Count; ++i)
{
learnedCats_second.Add((int)(((List<object>)learned_categories[i])[1]));
}
var pairs = pair(input_patterns.ToList<float[]>().ToArray(), learnedCats_second.ToArray());
var first_5_highest = firstN(5, count_highest(pairs.ToList<List<object>>()));
var list_to_translate = new List<List<float>>();
foreach (List<object> list in first_5_highest)
{
list_to_translate.Add((List<float>)list[0]);
}
//IEnumerable<List<List<float>>> fl = list_to_translate.Cast<List<List<float>>>();
return translate_into_events(translate_to_pitches(list_to_translate));
}
Does anyone know how I can get around this error?