The current CharsetDetector is ok if you have exclusive access to the file in question. If you are however analyzing files as they are in use by other processes, like with me, where I am analyzing log-files being written to by other processes, then it fails:
System.IO.IOException: 'The process cannot access the file '...\Application.log' because it is being used by another process.'
I see that the CharsetDetector uses this code to open the file:
using (FileStream fileStream = File.OpenRead(filePath))
I believe that File.OpenRead does not explicitly allow others to ReadWrite while itself is doing its own operations (if I have understood this right).
In my own program I extensively read the files myself, and I had the same issue myself - at first. I fixed it by adding some more information when opening the file, to make sure that access can be shared with others:
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
I don't remember exactly where I got it from, but I think MSDN docs + StackOverflow were my sources on this.
I believe that this should be a non-intrusive simple fix.
The current CharsetDetector is ok if you have exclusive access to the file in question. If you are however analyzing files as they are in use by other processes, like with me, where I am analyzing log-files being written to by other processes, then it fails:
I see that the CharsetDetector uses this code to open the file:
I believe that File.OpenRead does not explicitly allow others to ReadWrite while itself is doing its own operations (if I have understood this right).
In my own program I extensively read the files myself, and I had the same issue myself - at first. I fixed it by adding some more information when opening the file, to make sure that access can be shared with others:
I don't remember exactly where I got it from, but I think MSDN docs + StackOverflow were my sources on this.
I believe that this should be a non-intrusive simple fix.