diff --git a/src/Build/Construction/Solution/SolutionFile.cs b/src/Build/Construction/Solution/SolutionFile.cs index 909feaf74a6..63ce5b9dcee 100644 --- a/src/Build/Construction/Solution/SolutionFile.cs +++ b/src/Build/Construction/Solution/SolutionFile.cs @@ -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; @@ -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}"); - } } ///