There has to be an easier way - ReadLine text limit to 256 chars
Typical Friday afternoon problem. My console application works fine, the only problem is that Console.ReadLine maxs out at 256 characters. This application definitely needed the capacity for much larger strings and I didn't want to split it across multiple lines.
Searching for this problem I found nothing - it seems to be the default buffer size on the input stream attached to Console.In. But surely somebody else had hit this problem before??
Anyway, my solution is dirty. Dirty enough to post here and ask for a better one:
byte[] bytes = new byte[2560]; // or any large size you can imagine
// create a new input stream with the large buffer size
Stream inputStream = Console.OpenStandardInput(bytes.Length);
// read up to the length of tbe buffer
int bufferSize = inputStream.Read(bytes,0,bytes.Length);
// take two away for CR,LF
string command = Encoding.ASCII.GetString(bytes,0,bufferSize-Environment.NewLine.Length);
This works for any size buffer based on the size sent to the OpenStandardInput method.