Skip to content

Commit

Permalink
Add line/column information to invalid project exception (#11232)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliiaKovalova authored Jan 7, 2025
1 parent 8d395fd commit b497794
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/Build/Construction/Solution/SolutionFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -302,28 +302,36 @@ internal void ParseUsingNewParser()
{
ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(FullPath);

if (serializer != null)
if (serializer == null)
{
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
new BuildEventFileInfo(FullPath),
$"InvalidProjectFile",
$"No solution serializer was found for {FullPath}");
}
else
{
try
{
SolutionModel solutionModel = serializer.OpenAsync(FullPath, CancellationToken.None).Result;
SolutionModel solutionModel = serializer.OpenAsync(FullPath, CancellationToken.None).GetAwaiter().GetResult();
ReadSolutionModel(solutionModel);
}
catch (SolutionException solutionEx)
{
var errorLocation = ElementLocation.Create(FullPath, solutionEx.Line ?? 0, solutionEx.Column ?? 0);
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
new BuildEventFileInfo(errorLocation),
"InvalidProjectFile",
solutionEx.ToString());
}
catch (Exception ex)
{
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
new BuildEventFileInfo(FullPath),
$"InvalidProjectFile",
ex.ToString());
new BuildEventFileInfo(FullPath),
"InvalidProjectFile",
ex.ToString());
}
}
else if (serializer == null)
{
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
new BuildEventFileInfo(FullPath),
$"InvalidProjectFile",
$"No solution serializer was found for {FullPath}");
}
}

/// <summary>
Expand Down

0 comments on commit b497794

Please sign in to comment.