error MSB4025: The project file could not be loaded. Name cannot begin with the '<' character, hexadecimal value 0x3C.
after a merge means Git left conflict markers in the .csproj. The file is
no longer valid XML. Open it at the line the error names, choose the version you want,
delete the marker lines and build again.
The line and position in the message point straight at the first
<<<<<<< line. Keep one side of the conflict, remove
all three marker lines, then git add the file and finish the merge.
The error
...\MergeLab\MergeLab.csproj(11,2): error MSB4025: The project file could not be loaded. Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 11, position 2.
Build FAILED.
The project path is shortened; nothing else in the output was changed.
Why it happens
Two branches changed the same PackageReference line, one to 13.0.1 and one
to 13.0.2. git merge feature reported
CONFLICT (content): Merge conflict in MergeLab.csproj and wrote both
versions into the file between markers. Its last line,
Automatic merge failed; fix conflicts and then commit the result., is the
warning at merge time; if nobody reads it, the next build is often the first thing
that complains, as it was here. This is what the file held:
<ItemGroup>
<<<<<<< HEAD
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
=======
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
>>>>>>> feature
</ItemGroup>
MSBuild reads a project file as XML. Line 11 starts with
<<<<<<< HEAD, and the XML reader sees a
< that opens an element whose name begins with another
<, which XML forbids. That is the "hexadecimal value 0x3C" in the
message: 0x3C is the < character. The build stopped after 0.04 seconds
with this single error and nothing else, not even a restore line.
The fix
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>
dotnet build
git add MergeLab.csproj
With the markers gone and the 13.0.2 line kept, the build reported 0 errors, and after
git add and a commit, git status --short listed only the
untracked bin/ and obj/ folders. Decide which side is right
before you delete anything, and check why the other branch changed the line.
How it was reproduced
A dotnet new console project on .NET SDK 10.0.403 with Newtonsoft.Json
13.0.3 in a scratch Git repository. One branch set the version to 13.0.2, the main
branch to 13.0.1, and git merge feature produced the conflict.
dotnet build on the conflicted file failed as shown.
Frequently asked
- What does MSB4025 the project file could not be loaded mean?
- MSBuild could not parse the project file as XML. After a Git merge, conflict markers left in the csproj cause it; the line and position in the message point at them.
- What is hexadecimal value 0x3C in MSB4025?
- 0x3C is the less-than character. A conflict marker line starts with seven of them, which is not valid XML, so the reader stops at that line.
- How do I fix a Git merge conflict in a csproj?
- Open the file, keep the side you want between the markers, delete the three marker lines, build to check, then git add the file and commit the merge.
More decoded errors in the Fixes category.