VisualStudio 2013 strange compilation issues

Question

I am having some unusual compilation issues with Visual Studio 2013 and it really breaks my commands workflow.

The problem is difficult to explain, but I will give screenshots and code snippets to help people understand the problems we are facing.

We have a project that we recently moved to VisualStudio 2013 from 2010 and updated to .Net 4.5, the project is an ASP.NET Web Forms project.

The code compiles and works, but strangely, when I change any of the class files, sometimes even adding a comment 'Test Comment

, it doesn't compile.

The errors shown in the error window are getting weirder, and IntelliSense shows errors in the wrong place, some of the errors are even disabled entirely. Example: _To is not defined

on a string Dim _Town as String

or on the same string 'ring' is not defined

that is clearly part of the word String

ScreenShots

Here are some of the errors after I added the failing code at line 44 and then commented it out and re-compiled

Here are some of the errors after I added the error code on line 44 and then commented and recompiled enter image description here

What i tried

I tried to change the line endings in the files and make sure they are all Windows CR + LF, I tried tracking down in the build output for nothing I can actually see to help me. I even dropped the solution from control source on another machine to test and it had the same problem. It didn't actually compile at all on the new machine, but I don't know if the two questions are related.

+3


source to share


1 answer


I had the same problem as yours and also the same scenario (I updated a very old VB.NET project to a 2013 project).

The problem seems to be related to the encoding of the files. I don't know the exact reason, but may have multiple files with different encoding (in my case some files were ANSI, other files were UTF-8 with BOM).

If you are not sure if there are files with different encodings, open them in Notepad ++. You should see the file encoding in the bottom right corner.

I first convert the offending file to ANSI to see if that solves the problem. I opened the offending file in Notepad ++, chose Encoding-Convert to ANSI, Saved, Encoding-> Encode In UTF-8 without BOM, saved and reloaded the file in VS. The project is now compiling successfully.



However, I didn't want to do this every time I changed the file (since VS was converting it back to UTF8), so I copied all the old files (in my case they were only 4 files) to a temporary directory, deleted the files from VS and created new ones files with the same name and I copied / pasted the contents into each file. Now all my files are in UTF8 and I don't have this problem anymore.

The solution is to convert your files to ANSI as UTF8 or convert them to UTF8 (looks like this is the default encoding for newly generated files in Visual Studio, so I suggest converting them to UTF8)

If you have a lot of files, I think you can try converting them to UTF8 using Notepad ++.

Sincerely.

+1


source







All Articles