Gedit has problem opening file: invalid characters

Gedit 3.36.2 is showing an error when opening a file:

There was a problem opening the file “[…].txt”.
The file you opened has some invalid characters. If you continue editing this file you could corrupt this document.
You can also choose another character encoding and try again.

Gedit shows a banner indicating Character Encoding “Current Locale (UTF-8)” as selected, and the drop down box also has Unicode (UTF-16), selecting it does not seem to make a difference and the drop down box always goes back to showing UTF-8.

chardetect [file] shows UTF-16 with confidence 1.0.

Other editors like LIbreOffice, Pluma (on another system), and VS Code all open the file without issues. VS Code identifies the encoding as UTF-16LE.

What is going on with Gedit?

try open---->character Encoding—>Add or Remove—>select and add UTF-16LE —>select UTF-16LE—>open .

also you can use gsettings command ,Example ,

to get current setting .

gsettings get org.gnome.gedit.preferences.encodings candidate-encodings

to change setting .

gsettings set org.gnome.gedit.preferences.encodings candidate-encodings "['UTF-16LE']"

I did try opening with UTF-16LE and it had the same problem.

$ gsettings get org.gnome.gedit.preferences.encodings candidate-encodings