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

Visual Studio-2010Visual StudioVisual Studio-2008Visual Build-Professional

Visual Studio-2010 Problem Overview


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.

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

In my case it was the xxxxxxxxxxxx.vcxproj.user file that was causing the problem; it was blank after a crash. I renamed it and the problem went away.

Solution 2 - Visual Studio-2010

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>

Solution 3 - Visual Studio-2010

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.

To fix this in VS, open the file in VS and then depending on the version of VS

  • File > Advanced Save Options > choose an appropriate encoding
  • File > Save As > keep the filename, click the drop-down arrow on the right side of the save button to select an encoding

Solution 4 - Visual Studio-2010

In my case.I was getting missing element error pointing to NuGet.Config file. At that time it was looking some thing like this

<?xml version="1.0" encoding="utf-8"?>
<settings>
  <repositoryPath>Packages</repositoryPath>
</settings>

then I just added configuration tag that actually wraps entire xml. Now working fine for me

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <settings>
     <repositoryPath>Packages</repositoryPath>
  </settings>
</configuration>

Solution 5 - Visual Studio-2010

This error is caused by corrupted proj file.

Visual Studio always has backup project file at specific folder.

Please browse to:

C:\Users\<Your user>\Documents\Visual Studio <Vs version>\Backup Files\<your project>

You should see 2 files like this:

Original-May-18-2018-1209PM.<your project>.csproj
Recovered-May-18-2018-1209PM.<your project>.csproj

You only need copy file:

Original-May-18-2018-1209PM.<your project>.csproj

And re-name as

<your project>.csproj 

and override at root project folder.

Problem is solved!

Solution 6 - Visual Studio-2010

My project did not load and gave me a Root Element Missingerror. I just deleted ****.csproj.user file and reloaded it again. The problem was solved this way

Solution 7 - Visual Studio-2010

In my case, when I opened the .csproj file, it was empty so I went to my previous commit in git and copied the contents of that file and pasted it my current .csproj file. After which I deleted the .csproj.user file, reloaded my project, and everything started working again.

Solution 8 - Visual Studio-2010

I had this issue running VS 2017, on build I was getting the error that the 'root element was missing'. What solved it for me was going to Tools > Nuget Package Manager > Package Manager Settings > General > Clear all Nuget Caches. After doing that I ran the build again and it was fixed.

Solution 9 - Visual Studio-2010

I got same error. showing error Microsoft.Data.Entity could not loaded root element missing. When i delete that file from C:\Windows\Microsoft.NET\Framework\v4.0.30319 and again open my solution my problem was solved. Everything woks fine

Solution 10 - Visual Studio-2010

You can also search for the file. Navigate to your project directory with PowerShell and run Get-FileMissingRoot:

function Get-FileMissingRoot {
    
    dir -recurse |
        where {
            ($_ -is [IO.FileInfo]) -and 
            (@(".xml", ".config") -contains $_.extension) 
        } |
        foreach {
            $xml = New-Object Xml.XmlDocument;
            $filename = $_.FullName
            try {
                $xml.Load($filename)
            }
            catch {
                write ("File: " + $filename)
                write ($_.Exception.Message)
            }
        }
}

Solution 11 - Visual Studio-2010

In my case, .csproj was changed to encoded format. I did undo changes to csproj in Git(Team explorer) and reloaded the project file. This solved the problem.

Solution 12 - Visual Studio-2010

In my case, the file C:\Users\xxx\AppData\Local\PreEmptive Solutions\Dotfuscator Professional Edition\4.0\dfusrprf.xml was full of NULL.

I deleted it; it was recreated on the first launch of Dotfuscator, and after that, normality was restored.

Solution 13 - Visual Studio-2010

This error can sometimes occur when you edit some Project Toolchain settings Atmel Studio 6.1.2730 SP2.

In my case I tried to edit Project Properties > Toolchain > Linker > General settings with 'All Configurations' selected in the Configuration. When I checked or unchecked a setting, a dialog with the error popped up. However, I found that I could make the same edits if I made them to only one build configuration at a time; i.e. with only 'Debug' or 'Release' selected instead of 'All Configurations'.

Interestingly, I later was able to edit the same Linker settings even with 'All Configurations' selected. I don't know what changed in my project that made this possible.

Solution 14 - Visual Studio-2010

I had Blue Screen while running Visual Studio 2013, when I Restart I intended to run again my project, but I had always this headius Error. anyway

Deleting The Folders with the Temp info Fix this problem. in my case the Project was a Windows Server, and Basically it Creates a Folder with some Tem info.

the folder was

C:\Users\User_NAME\AppData\Local\NAme_OF_THeProject

inside Exist a Folder with the Name of the Project+ some Generated GUI Service.ServerHostLoader_Url_u2jn0xkgjf1th0a3i2v03ft15vj4x52i

this is the Folder I deleted and now I can run again the Project.

Solution 15 - Visual Studio-2010

In my case I upgraded to VS2017 and wanted to build all projects with MSBuild 4 with my build script (which had been using MSBuild 3.5 when we were using VS2015). That MSBuild upgrade appeared fine for the Windows desktop applications but the ones for Windows CE with compact framework would give me this confusing error. Reverting to MSBuild 3.5 for Windows CE projects fixed the issue for me.

I did have the BOM in .csproj files by the way and removed them for all projects in a solution that would not build but that did not help.

Solution 16 - Visual Studio-2010

In xamarin form project. I deleted

.VS Project folder.
ProjectName.Android.csProj.User
ProjectName.Android.csProj.bak

Solution 17 - Visual Studio-2010

In my case I received a message like this: See this picture

I just commented the snipped code below in the project file (.csproj) and the problem was fixed.

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

Solution 18 - Visual Studio-2010

In my case xxxx.pubxml.user was not loaded when tried to publish the application. I deleted the file and restart the Visual studio then created a new profile to publish it, problem is solved and published successfully.

Solution 19 - Visual Studio-2010

Hey, I have the same issue on Mac working on a Cocoa C# solution. (But I solved it !)

It always say that the root element is missing so it cannot load my C# project file.

I have the 2017 Visual Studio Mac Community Edition. I finally managed to find a solution after several hours (painful!).

My solution is because the frameworks related to the Visual Studio are old or broken. I found this because I tried to create a new Mac solution by Cocoa and it said "failed to save the solution". Then, I tried to create an Android Solution and it is working fine. Go to your "Finder" and "Go" -> "Go to a Folder" then go to the "Library/Frameworks". I have deleted mono.framework and frameworks related to Xamarin because I believe these Xamarin frameworks are broken.

Then, uninstalled the Visual Studio and reinstalled it. Now everything works fine!

Solution 20 - Visual Studio-2010

In my case, I just renamed the .csproj.user and restart the visual studio and opened the project. It automatically created another .csproj.user file and the solution worked fine for me.

Solution 21 - Visual Studio-2010

Ho i simply solved this issue by going to source control explorer and selected the issue project, right clicked and selected the option Get Specific Version under Advanced menu. And then selected Type as Latest Version and ticked following two check boxes and clicked Get button. Then i refreshed the solution and my project came back to live and problem gone. Please note that This may overwrite your local projects so your current changes may lose. So if you dont have any issues with your local copy then you can try this. Hope it helps

Solution 22 - Visual Studio-2010

I got this issue on a Web API project. Finally figured out that it was in my "///" method comments. I have these comments set to auto-generate documentation for the API methods. Something in my comments made it go crazy. I deleted all the carriage returns, special characters, etc. Not really sure which thing it didn't like, but it worked.

Solution 23 - Visual Studio-2010

In my case the RDLC files work with resource files (.resx), I had this error because I hadn't created the correspondent resx file for my rdlc report.

My solution was add the file .resx inside the App_LocalResources in this way:

\rep
\rep\myreport.rdlc
\rep\App_LocalResources\myreport.rdlc.resx

Solution 24 - Visual Studio-2010

I had a few massive VS2015 Community crashes.

> Delete all the .csproj.user files

which were full of null characters, and also these

> C:\Users\UserName\AppData\Local\Temp
> > .NETFramework,Version=v4.0.AssemblyAttributes.cs > .NETFramework,Version=v4.5.AssemblyAttributes.cs > .NETFramework,Version=v4.5.2.AssemblyAttributes.cs

Solution 25 - Visual Studio-2010

In my case, I got this error because of an empty packages.config file. This caused the NUGET package manager to fail and show the error Root element is missing. The resolution was to copy over elements from another non-empty file and then change it according to the needs.

Example (packages.config):

<?xml version="1.0" encoding="utf-8"?>
<packages>
 <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net451"/>
 <package id="Newtonsoft.Json" version="5.0.4" targetFramework="net451"/>
</packages>

Solution 26 - Visual Studio-2010

In my case, i was using vs 2010 with crystal report. Innerexception revealed root element is missing error. Go to directory like C:\Users\sam\AppData\Local\dssms\dssms.vshost.exe_Url_uy5is55gioxym5avqidulehrfjbdsn13\1.0.0.0 which is given in the innermessage and make sure user.config is proper XML (mine was blank for some reason).

Solution 27 - Visual Studio-2010

Deleting the .user file is exactly what fixed the problem for me. Lightning strike near the office shut my PC down and corrupted my .user file and project wouldn't load. I opened the file in Notepad++ and the "spaces" turned out to be [NULL] characters. Deleted the .user file and the file loaded!

source https://forums.asp.net/t/1491251.aspx?Can+t+load+project+because+root+element+is+missing+

Solution 28 - Visual Studio-2010

I had the same problem in a Xamarin Forms project. iOS project was unavailable and I couldn't reload the project. I was looking for a solution that doesn't need uninstalling anything.

The answer I got from this blog: https://dev.to/codeprototype/xamarin-form-application-failed-to-load-android-project-root-element-missing--27o0

So without uninstalling anything, you could delete the .csproj.user file (or rename it) so Visual Studio will create the file again. Worked for me twice.

Solution 29 - Visual Studio-2010

In my case the problem occurred due to closing my PC while visual studio were remain open, so in result csproj.user file saved empty. Thankfully i have already backup, so i just copied all xml from csproj.user and paste in my affected project csproj.user file ,so it worked perfectly.

This file just contain building device info and some more.

Solution 30 - Visual Studio-2010

No one of these solutions fixed my problem.

In my case, I finished my work and I shut down my computer. The day after I wasn't able to compile my project. I tried some of these solutions and I realized all my projects weren't work.

To Fix it, I reinstall .net core Framework.

Visual Studio 2017

Solution 31 - Visual Studio-2010

In my case Microsoft.Common.CurrentVersion.targets was corrupted. I copied this file from other system and it worked.

Solution 32 - Visual Studio-2010

Strangely "Root element is missing." also appears when no JDK was found.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGerhard WeissView Question on Stackoverflow
Solution 1 - Visual Studio-2010ElliotView Answer on Stackoverflow
Solution 2 - Visual Studio-2010OdedView Answer on Stackoverflow
Solution 3 - Visual Studio-2010stombeurView Answer on Stackoverflow
Solution 4 - Visual Studio-2010Malik KhalilView Answer on Stackoverflow
Solution 5 - Visual Studio-2010user3037124View Answer on Stackoverflow
Solution 6 - Visual Studio-2010Fereshteh MirjaliliView Answer on Stackoverflow
Solution 7 - Visual Studio-2010Alf MohView Answer on Stackoverflow
Solution 8 - Visual Studio-2010Shawn HillView Answer on Stackoverflow
Solution 9 - Visual Studio-2010user4481951View Answer on Stackoverflow
Solution 10 - Visual Studio-2010Sam PorchView Answer on Stackoverflow
Solution 11 - Visual Studio-2010Archana RView Answer on Stackoverflow
Solution 12 - Visual Studio-2010pascalView Answer on Stackoverflow
Solution 13 - Visual Studio-2010ptschnackView Answer on Stackoverflow
Solution 14 - Visual Studio-2010emamonesView Answer on Stackoverflow
Solution 15 - Visual Studio-2010Martin MaatView Answer on Stackoverflow
Solution 16 - Visual Studio-2010A.GoutamView Answer on Stackoverflow
Solution 17 - Visual Studio-2010Eduardo SobrinhoView Answer on Stackoverflow
Solution 18 - Visual Studio-2010Muhammad MasudView Answer on Stackoverflow
Solution 19 - Visual Studio-2010Can GaoView Answer on Stackoverflow
Solution 20 - Visual Studio-2010MBAView Answer on Stackoverflow
Solution 21 - Visual Studio-2010Nithin PaulView Answer on Stackoverflow
Solution 22 - Visual Studio-2010JarretteView Answer on Stackoverflow
Solution 23 - Visual Studio-2010WilsonView Answer on Stackoverflow
Solution 24 - Visual Studio-2010CRiceView Answer on Stackoverflow
Solution 25 - Visual Studio-2010MattView Answer on Stackoverflow
Solution 26 - Visual Studio-2010Nie SelamView Answer on Stackoverflow
Solution 27 - Visual Studio-2010Shailendra bindView Answer on Stackoverflow
Solution 28 - Visual Studio-2010TharinduView Answer on Stackoverflow
Solution 29 - Visual Studio-2010MirView Answer on Stackoverflow
Solution 30 - Visual Studio-2010AFetterView Answer on Stackoverflow
Solution 31 - Visual Studio-2010Vivek PandeyView Answer on Stackoverflow
Solution 32 - Visual Studio-2010MaxFmiView Answer on Stackoverflow