From a8fa5cb1dd269c6848c5d1e6c32074e25ca59ff5 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Tue, 7 Jan 2025 12:57:12 +0100 Subject: [PATCH 1/2] add line/column to invalid project expection --- .../Construction/Solution/SolutionFile.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Build/Construction/Solution/SolutionFile.cs b/src/Build/Construction/Solution/SolutionFile.cs index 909feaf74a6..68892206db0 100644 --- a/src/Build/Construction/Solution/SolutionFile.cs +++ b/src/Build/Construction/Solution/SolutionFile.cs @@ -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.Message); + } 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}"); - } } /// From 9247ac2ff57279f65033cb065ff8292539ca8e6d Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:35:08 +0100 Subject: [PATCH 2/2] return a callstack to the exception --- src/Build/Construction/Solution/SolutionFile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Build/Construction/Solution/SolutionFile.cs b/src/Build/Construction/Solution/SolutionFile.cs index 68892206db0..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; @@ -322,7 +322,7 @@ internal void ParseUsingNewParser() ProjectFileErrorUtilities.ThrowInvalidProjectFile( new BuildEventFileInfo(errorLocation), "InvalidProjectFile", - solutionEx.Message); + solutionEx.ToString()); } catch (Exception ex) {