TryParseOldStyleProjects throws "Sequence contains more than one element" when ASP.NET project contains project references

Open Beginner friendly
#685 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
csharp
Domain
backend

Research direction

Start in IISExpressLaunchDetailsExtensions.TryParseOldStyleProjects, where the old-style csproj XML is loaded and the Project element is selected. Reproduce with an ASP.NET Framework project containing a referenced class library and no launchProfile.json; done means AddIISExpressProject no longer throws and the old project metadata is parsed successfully.

Written by the indexing model from the issue text.

Description

Needs: Triage :mag:
Describe the bug

AddIISExpressProject from Aspire.Hosting.IncrementalMigration will throw an InvalidOperationException ("Sequence contains more than one element") if the referenced ASP.NET project itself contains project reference (which would be all but the most simple sites) and a launchProfile.json doesn't exist (i.e. reading from the old-style csproj itself).

In IISExpressLaunchDetailsExtensions.TryParseOldStyleProjects, after the csproj is loaded as an xml document, an attempt to grab the root <Project> is made (doc.Descendants(MsbuildNS + "Project").SingleOrDefault()). However Descendants grabs all <Project> nodes, which includes those that are children of <ProjectReference>, which trips the SingleOrDefault.

To Reproduce

Create a class library project and add it as a project reference to the ASP.NET Framework project referenced by the Aspire AppHost.

This repo+branch also reproduced the issue:
https://github.com/Sebbs128/AspireNetFramework/tree/update-to-swa-hosting-package

Exceptions (if any)

System.InvalidOperationException 'Sequence contains more than one element'
Stacktrace

   at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at Aspire.Hosting.IISExpressLaunchDetailsExtensions.TryParseOldStyleProject(String path, IISExpressLaunchDetails& metadata)
   at Aspire.Hosting.IISExpressLaunchDetailsExtensions.GetLaunchDetails(IProjectMetadata metadata)
   at Aspire.Hosting.IISExpressProjectExtensions.AddIISExpressProject[TProject](IDistributedApplicationBuilder builder, String name)
   at Program.<Main>$(String[] args) in D:\\source\\AspireNetFramework\\samples\\AspireNetFramework.Samples.AppHost\\Program.cs:line 9
Further technical details

Please include the following if applicable:

ASP.NET Framework Application:

  • Technologies and versions used (i.e. MVC/WebForms/etc): MVC
  • .NET Framework Version: 4.8
  • IIS Version: IISExpress 10.0.26013.1000
  • Windows Version: Windows 11 (100.22621)

ASP.NET Core Application:

  • Targeted .NET version: 10
  • .NET SDK version: 10.0.300
Dominant language
C#
Stars
384
Forks
76
Avg merge
2h 24m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/systemweb-adapters

All issues in dotnet/systemweb-adapters

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.