Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling of empty packages sequence #1195

Merged
merged 7 commits into from
Feb 26, 2024
Merged

fix: handling of empty packages sequence #1195

merged 7 commits into from
Feb 26, 2024

Conversation

cslong
Copy link
Contributor

@cslong cslong commented Feb 22, 2024

The call to .First() was throwing exemption if the sequence contains no elements. In the call stack it's being hidden within the .ToDictionary since the methods are chained.

Related issue

TT: P119178698

Description

  • Update First() to FirstOrDefault() and handle null case to better handle sequence contains no elements error. This error was occurring when the PackageReference did not contain the version attribute. It would also throw in the PackageReference was missing the include, but that case is probably an invalid project file.

See project file here: https://github.com/neerajhanda/AspNetCore.BookStore/blob/master/src/AspNetCore.Bookstore.Web/AspNetCore.Bookstore.Web.csproj

Error: PortingAssistant.Client.PortingProjectFile.PortingProjectFileHandler: Error while creating project file for {projectfile} - System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at CTA.Rules.ProjectFile.ProjectFileCreator.<>c.b__30_1(XElement d)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Lookup2.Create(IEnumerable1 source, Func2 keySelector, IEqualityComparer1 comparer) at System.Linq.GroupedEnumerable2.GetEnumerator()
at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer`1 comparer)
at CTA.Rules.ProjectFile.ProjectFileCreator.UpdatePackageReferences()
at CTA.Rules.ProjectFile.ProjectFileCreator.CreateContents()

Supplemental testing

Add two unit tests that step through the new code to verify the functionality.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The call to .ToDictionary was throwing exemption if the sequence contains no elements.
* verify add new packages, and maintain existing
* verify no exception for no packages
* verify no exception for packages removed because existing
First() will throw exception if the Version or Include attributes are not found
In response to change in the datastore, aws/porting-assistant-dotnet-datastore@ba2603d. .NET 7 should be getting a specific version of the Microsoft.EntityFrameworkCore
In response to change in the datastore, aws/porting-assistant-dotnet-datastore@ba2603d. .NET 7 should be getting a specific version of the Microsoft.EntityFrameworkCore
@cslong cslong merged commit 1a7f08b into main Feb 26, 2024
1 check passed
@cslong cslong deleted the fix_seq_no_elements branch February 26, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants