Closed alexandrucatalinene closed 1 month ago
Thanks for reporting. Could you post the source of your User
class?
Sure. Sorry for the late reply
public class User
{
public int Id { get; set; }
public required string Name { get; set; }
public required string DeviceId { get; set; }
public required string Password { get; set; }
}
I also managed to obtained a stacktrace of the error
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
at System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Riok.Mapperly.Descriptors.MappingBodyBuilders.ObjectMemberMappingBodyBuilder.BuildMappingBody(IMembersContainerBuilderContext`1 ctx) in /_/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/ObjectMemberMappingBodyBuilder.cs:line 30
at Riok.Mapperly.Descriptors.MappingBodyBuilders.NewInstanceObjectMemberMappingBodyBuilder.BuildMappingBody(MappingBuilderContext ctx, NewInstanceObjectMemberMethodMapping mapping) in /_/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs:line 36
at Riok.Mapperly.Descriptors.MappingBodyBuilders.MappingBodyBuilder.BuildMappingBodies(CancellationToken cancellationToken) in /_/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MappingBodyBuilder.cs:line 27
at Riok.Mapperly.Descriptors.DescriptorBuilder.Build(CancellationToken cancellationToken) in /_/src/Riok.Mapperly/Descriptors/DescriptorBuilder.cs:line 84
at Riok.Mapperly.MapperGenerator.BuildDescriptor(CompilationContext compilationContext, MapperDeclaration mapperDeclaration, MapperConfiguration mapperDefaults, CancellationToken cancellationToken) in /_/src/Riok.Mapperly/MapperGenerator.cs:line 80
at Riok.Mapperly.MapperGenerator.<>c.<Initialize>b__2_3(ValueTuple`2 x, CancellationToken ct) in /_/src/Riok.Mapperly/MapperGenerator.cs:line 48
at Microsoft.CodeAnalysis.UserFunctionExtensions.<>c__DisplayClass0_0`2.<WrapUserFunction>b__0(TInput input, CancellationToken token)
I cannot reproduce this, do you have any additional configuration? Any mapperly related attributes or properties (e.g. MapperlyDefaults
)? Could you share a minimal repro as a GitHub repo/gist?
Yes I have
[assembly: MapperDefaults(EnumMappingIgnoreCase = true, ThrowOnMappingNullMismatch = false)]
but even when I comment this part it still errors out.
Also, I tried on two different computers with a similar setup and it does the same.
It could be something I have configured but I don't know what could it be.
I attached an empty Web Api project with Mapperly that reproduces the errors for me.
Mhmm I still cannot reproduce it, the projects builds perfectly fine on my machine (unfortunately I don't have a windows machine by hand and therefore no visual studio). Can you build the docker container? Can you build the project on the CLI?
Update. I tried it on the same machine but with Rider 2024.1.2 and it works.
Does it work on the cli and in docker?
It works with cli - didn't try it with docker but it's probably the same since it's also cli.
So, this leads me to believe it has something to do with VS
Unfortunately I don‘t have easy access to a windows machine and VS, and therefore cannot reproduce this. Maybe one of the previous comitters with a win machine could look into this @CommonGuy @TimothyMakkison @trejjam 😊
I can try to take a look
I was able to reproduce the issue. It's happening only in VS (tested VS 2022, CLI .NET 8, Rider 2024.1.4).
(screenshots are from Rider, but it's attached debugger from VS)
The state after retrieving the first item from EnumerateUnmappedOrConfiguredTargetMembers
in the ObjectMemberMappingBodyBuilder
.BuildMappingBody
:
The state changes after BuildMemberAssignmentMapping
(Id
is removed from _unmappedTargetMemberNames
):
Exception from the HashSet.Enumerator.MoveNext
:
PR fixing the issue: #1438
Describe the bug A clear and concise description of what the bug is. I have a very simple mapping made from a model to a dto but it seems it doesn't work. I get this error in the console (Visual Studio 2022)
The code gets generated but it's not included in the build so it gives an error.
Declaration code
Actual relevant generated code
Expected relevant generated code
Environment (please complete the following information):
Additional context Simple dotnet minimap API project.