views:

46

answers:

3

How to fix "Root element is missing." when doing a Visual Studio (VS) Build?

Any idea what file I should look at in my solution?

Actually, I am getting this error message inside of "Visual Build Pro" when using using the "Make VS 2008" command. This command works just fine when building other solutions (like about 20) and I am not really sure why mine is getting the error.

Any help would be very much appreciated. :)

I am using VS 2008 and Visual Build Pro 6.7.

+1  A: 

Make sure any XML file (or any file that would be interpreted as an XML file by visual studio) has a correct XML structure - that is, one root element (with any name, I have use rootElement in my example):

<?xml version="1.0"?> 
<rootElement>
 ...
</rootElement>
Oded
There are like thousands of files in my solution. Any special extensions to look at?
Gerhard Weiss
@Gerhard Weiss - .xml, .config, .xsd, .xsl would be a good start. If you have any XHTML files, they are also good candidates. I don't know anything about your project and what kind of files you have in it, so I can't really tell you. However, look at the error in the error window - it should tell you which file is causing the problem.
Oded
+1  A: 

You will also get 'root element is missing' when the BOM strikes :). BOM = byte order mark. This is an extra character that gets added to the start of a file when it is saved with the wrong encoding.
This can happen sometimes in Visual Studio when working with XML files. You can either code something to remove it from all your files, or if you know which file it is you can force visual studio to save it with a specific encoding (utf-8 or ascii IIRC).

If you open the file in an editor other than VS (try notepad++), you will see two funny characters before the <? xml declaration.

StephaneT
A: 

Thank you both for your answers. I did find a null file with a .vbproj extension and that was the culprit.

Gerhard Weiss