Visual Studio Encoding Issues

I have problems encoding files in Visual Studio 2008. When compiling, I get errors like this:

alt text

When I try to open a file where a specific error occurs, an encoding window appears:

alt text

Defined by auto-detect defualt. When I change the encoding to UTF-8, everything works. If I open every problem file in my project using UTF-8 encoding, the project starts compiling. The problem is that I have too many files, and it’s funny to open each file and set the encoding to UTF-8. Is there any way to do this fast?

My VS settings:

alt text

I am using Windows Server 2008 R2.

UPDATE:

For Hans Passan and Noah Richards. Thanks for the interaction. I recently changed my operating system, so everything is fresh. I also downloaded the new solution from the control source.

In the regional OS settings, I changed the system language to Polish (Poland):

alt text

In VS, I changed the international settings in the same way as the windows:

alt text

The problem is still not resolved.

When I open some .cs files using automatic detection for encoding and then check Files → Advanced save options ... some of these .cs files have code page 1250:

alt text

but internally looks like this:

alt text

It is connected because when I check the properties of such specific files in the source control, they seem to be UTF-8 encoded:

alt text

I do not understand this discrepancy.

All other files are UTF-8 encoded:

alt text

and opens correctly. I have no idea what is happening, because, as far as I know, my friend has the same parameters as me, and the same project compiles it correctly. But so far, he has not happily encountered coding problems.

+7
visual-studio-2008 visual-studio
source share
2 answers

In this uppercase A with circumflex, I am informed that the file is UTF-8 (if you look with a hex editor, you will probably see that the bytes are C2 A0). This is inextricable space in UTF-8.

Visual Studio does not detect the encoding, because (most likely) the file does not have enough high-character ASCII characters to help in reliable detection.

In addition, there is no specification (bytes). This will help with detection (this is the “signature” in the description of “UTF-8 with signature”).

What you can do: add a specification to all files that don't have them. How to add? Create a file with a specification only (empty file in Notepad, Save As, select UTF-8 as the encoding). This will be 3 bytes (EF BB BF). You can copy this at the beginning of every file that has no specification:

copy /b/v BOM.txt + YourFile.cs YourFile_Ok.cs ren YourFile.cs YourFile_Org.cs ren YourFile_Ok.cs YourFile.cs 

Make sure that there is a + symbol between the specification file name and the original file.

Try using one or two files, and if that works, you can create a batch file for this. Or a small C # application (since you are a C # programmer) that can determine if a file already has a specification or not, so you do not add it twice. Of course, you can do this in almost everything: from Perl to PowerShell to C ++ :-)

+2
source share

Once you have opened the files in UTF-8 mode, try changing the advanced file saving options and saving it (as UTF-8 with a signature if you think these files should be UTF-8)?

Automatically detecting encoding is the best effort, so something in the file probably causes it to be detected as something other than UTF-8, for example, the presence of only ASCII characters in the first kilobyte of the file, or having a specification that indicates that the file is something other than UTF-8. Re-saving the file as UTF-8 with the signature should (hopefully) fix this.

If this continues after this, let me know, and we can try to track what makes them create / save in the first place.

0
source share

All Articles