I have this C# code in a macOS Island console application using RTL:
static class Program
{
public static Int32 Main(string[] args)
{
string filePath = "/Users/garry/Desktop/test.possum";
if (File.Exists(filePath))
{
Console.WriteLine("File exists");
string s = File.ReadText(filePath);
Console.Write(s);
}
}
}
The console prints out “File Exists” but then the app crashes with this message:
~> Process Test macOS App started
File exists
~> Ignored exception of type RemObjects.Elements.System.Exception on thread 380A
~> Message: Array index 0 is outside of the valid range (array is empty)
Uncaught exception: RemObjects.Elements.System.IndexOutOfRangeException: Array index 0 is outside of the valid range (array is empty)
~> Process Test macOS App terminated with exit code 255. Ran for 2.069
At first I thought it might be because I hadn’t supplied an encoding to the ReadText()
method but the same crash happens with File.ReadText(filePath, Encoding.UTF8)
too.
Where’s the array index issue? I’m assuming it’s in RTL somewhere?
Here’s the contents of the file (if it makes a difference):
var x = "global"
function outer():
var x = "outer"
function inner():
print x;
inner()
outer()