Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/Microsoft.VisualStudio.SolutionPersistence/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@
<value>Missing or invalid scope.</value>
<comment>Error message</comment>
</data>
<data name="InvalidProjectType" xml:space="preserve">
<value>Missing or invalid project type guid.</value>
<comment>Error message</comment>
</data>
<data name="SyntaxError" xml:space="preserve">
<value>Syntax error.</value>
<comment>Error message</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ private SolutionItemModel ReadProjectInfo(SolutionModel solution, ref StringToke
StringSpan projectType = tokenizer.NextToken(SlnConstants.ProjectSeparators);

// but it must end with [sep]) ... checked later.
this.SolutionAssert(Guid.TryParse(projectType.ToString(), out Guid projectTypeId), Errors.InvalidProjectType);
if (!Guid.TryParse(projectType.ToString(), out Guid projectTypeId))
{
projectTypeId = Guid.Empty;
this.tarnished = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly does marking it as tarnished do. Is there other functionality that is hidden behind the tarnished flag or is it mainly for logging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indicates that a property was missing and when loaded by a designer like VS it marks the file as modified, so it gets resaved. The sln parser is very forgiving of reading with different errors. We don't rely on this when parsing slnx as the parser is much stricter.

}

// this just skips up to Display's name "App1" first quote, position at 'A". The TrimStart is extension to allow spaces before ')';
// and yes, any characters are allowed for example // Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App1", valid bad format :P "App1\App1.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,19 @@ public async Task DuplicateProjectIdSlnxAsync()
}

/// <summary>
/// Checks that an error is thrown if the solution contains an invalid project type id.
/// Verifies that a malformed project type id is loaded as an empty guid without errors, and
/// the solution is marked as tarnished.
/// </summary>
[Fact]
public async Task InvalidProjectTypeSlnAsync()
{
ResourceStream invalidProjectType = SlnAssets.LoadResource("Invalid/InvalidProjectType.sln");
SolutionException ex = await Assert.ThrowsAsync<SolutionException>(
async () => _ = await SolutionSerializers.SlnFileV12.OpenAsync(invalidProjectType.Stream, CancellationToken.None));
Assert.StartsWith(Errors.InvalidProjectType, ex.Message);
Assert.Equal(5, ex.Line);
Assert.Null(ex.Column);
SolutionModel solution = await SolutionSerializers.SlnFileV12.OpenAsync(invalidProjectType.Stream, CancellationToken.None);
Assert.NotNull(solution.SerializerExtension);
Assert.True(solution.SerializerExtension.Tarnished);

SolutionProjectModel? project = solution.FindProject("InvalidProjectType.csproj");
Assert.NotNull(project);
Assert.Equal(Guid.Empty, project.TypeId);
}
}