I have a chrome native messaging host application that reads JSON messages from STDIN and writes data to STDOUT.
The problem I am facing right now is with the StreamReader.Peek()
method.
On debugging on first iteration it runs successfully, but on second iteration it breaks at reader.Peek() point with out throwing any exception.
The control just goes away without any exception.
var length = 0;
var lengthBytes = new byte[4];
stdin.Read(lengthBytes, 0, 4);
length = BitConverter.ToInt32(lengthBytes, 0);
var messageBuffer = new char[length];
using (var reader = new StreamReader(stdin))
{
while (reader.Peek() >= 0)
{
reader.Read(messageBuffer, 0, messageBuffer.Length);
}
}
var message = new string(messageBuffer);
Log.Debug(message);
var jsonMessageObject = JsonConvert.DeserializeObject<JObject>(message);
if (jsonMessageObject == null)
{
return null;
}
Can someone help how to know whats going wrong even though it had read all the data perfectly?
Why is Peek()
breaking without any exception?