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

Building Riok.Mapperly.IntegrationTests fails with "Generator 'MapperGenerator' failed to generate source..." in VS 2022.17.11.4 #1516

Closed
IanKemp opened this issue Oct 5, 2024 · 0 comments · Fixed by #1517
Labels
bug Something isn't working

Comments

@IanKemp
Copy link
Contributor

IanKemp commented Oct 5, 2024

Describe the bug
As title.

Additional context
Running msbuild -fl from the root of the repo yields

  Microsoft (R) Visual C# Compiler version 4.11.0-3.24460.3 (5649376e)
  Copyright (C) Microsoft Corporation. All rights reserved.
CSC : warning CS8785: Generator 'MapperGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidOperationException' with message 'Collection was modified; enumeration operation may not execute.'. [<redacted>\mapperly\test\Riok.Mapperly.IntegrationTests\Riok.Mapperly.IntegrationTests.csproj]
  System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
  at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
  at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
  at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
  at Riok.Mapperly.Descriptors.MappingBodyBuilders.ObjectMemberMappingBodyBuilder.BuildMappingBody(MappingBuilderContext ctx, IMemberAssignmentTypeMapping mapping) in /_/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/ObjectMemberMappingBodyBuilder.cs:line 21
  at Riok.Mapperly.Descriptors.MappingBodyBuilders.MappingBodyBuilder.BuildMappingBodies(CancellationToken cancellationToken) in /_/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MappingBodyBuilder.cs:line 39
  at Riok.Mapperly.Descriptors.DescriptorBuilder.Build(CancellationToken cancellationToken) in /_/src/Riok.Mapperly/Descriptors/DescriptorBuilder.cs:line 86
  at Riok.Mapperly.MapperGenerator.BuildDescriptor(CompilationContext compilationContext, MapperDeclaration mapperDeclaration, MapperConfiguration mapperDefaults, CancellationToken cancellationToken) in /_/src/Riok.Mapperly/MapperGenerator.cs:line 87
  at Riok.Mapperly.MapperGenerator.<>c.<Initialize>b__2_3(ValueTuple`2 x, CancellationToken ct) in /_/src/Riok.Mapperly/MapperGenerator.cs:line 55
  at Microsoft.CodeAnalysis.TransformNode`2.<>c__DisplayClass6_0.<.ctor>b__0(TInput i, CancellationToken token)
  at Microsoft.CodeAnalysis.TransformNode`2.UpdateStateTable(Builder builder, NodeStateTable`1 previousTable, CancellationToken cancellationToken)

The offending method ObjectMemberMappingBodyBuilder.BuildMappingBody(MappingBuilderContext, IMemberAssignmentTypeMapping) contains the following code:

        // init only members should not result in unmapped diagnostics for existing target mappings
        foreach (var initOnlyTargetMember in mappingCtx.EnumerateUnmappedTargetMembers().Where(x => x.IsInitOnly))
        {
            mappingCtx.SetTargetMemberMapped(initOnlyTargetMember);
        }

Forcing an explicit materialisation of the collection used in this foreach fixes the issue and all tests pass:

foreach (var initOnlyTargetMember in mappingCtx.EnumerateUnmappedTargetMembers().Where(x => x.IsInitOnly).ToArray())

This is similar to #1403 and its fix #1438.

@IanKemp IanKemp added the bug Something isn't working label Oct 5, 2024
@IanKemp IanKemp mentioned this issue Oct 5, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant