I am having an issue with Native Messaging where the host is written in C# (NET 8.0) and running under MS Windows. For certain messages sent from my extension to the host, the number of bytes read from stdin is less than the expected number which is written as a prefix to the message.
For example, a message will begin with 0x95ff2400, which is 2,424,725 (0x24ff95 from 0x95ff2400). However, the C# StreamReader.Read() method will only read 2,422,968 bytes, i.e., 1,757 less than expected.
It is not the case that a subsequent call to StreamReader.Read()will yield the "missing" bytes. In fact, all the available bytes has been read.
The issue seems to be character encoding.
At present, I open stdin with "Console.OpenStandardInput()". I do not explicitly set the encoding. I do not recall why I did not consider possible encoding issues when I wrote the code, but I was probably following some example.
Given the Native Messaging protocol specifies a prefix that is in BYTES, I presume I should configure the Console class in C# to read raw bytes and not decode them. I believe the Console class requires stdin and stdout to use the same encoding. So, I'll have to convert from bytes -> characters on stdin and convert from characters -> bytes on stdout.
Does my analysis of the issue and plan to fix it make sense?
Are there any example C# Native Messaging host programs that demonstrate the correct way to read/write the Native Messaging protocol?
--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/2ae8c5e0-30d7-4198-b07d-ff3f40e80c6an%40chromium.org.