Closed msneijders closed 1 year ago
Looks like the mapper recursively calls itself when UseDeepCloning
is enabled. Object-> Object will run and cause a stackoverflow, Object? -> Object? will crash my ide.
My minimal reproducible example:
var copy = MyMapper.Clone("Hello World");
Console.WriteLine(JsonSerializer.Serialize(copy, new JsonSerializerOptions { WriteIndented = true }));
[Mapper(UseDeepCloning = true )]
public static partial class MyMapper
{
public static partial object Clone(object f);
// uncommenting this will crash my ide
//public static partial object? Clone(object? f);
//uncomment this and it fixes it
//private static object ObjectToObject(object t) => t;
}
#nullable enable
public static partial class MyMapper
{
public static partial object Clone(object f)
{
return (object)Clone(f);
}
}
Currently SpecialTypeMappingBuilder
will attempt to map the source to itself when target is an object
. Unfortunately when source is also an object a recursive call can be created. By adding an additional branch to SpecialTypeMappingBuilder
we can prevent this from happening.
This probably isn't a good solution as a shallow clone will be used instead of deep clone. Perhaps it would be better to avoid creating a mapping and raise a warning instead.
return ctx.Target.SpecialType switch
{
SpecialType.System_Object when ctx.MapperConfiguration.UseDeepCloning && ctx.Source.SpecialType == SpecialType.System_Object
=> new DirectAssignmentMapping(ctx.Source),
public static partial class MyMapper
{
public static partial object Clone(object f)
{
return f;
// return f == null ? default : f; // for object? -> object?
}
}
Thank you for the bug report, I think your fix makes sense to improve the reliability of Mapperly. Feel free to open a PR.
However this should IMO only be a problem if there is a mapping method definition with source and target type object
, but not for your first example 🤔
:tada: This issue has been resolved in version 2.8.0-next.2 :tada:
The release is available on:
v2.8.0-next.2
Your semantic-release bot :package::rocket:
I have the same problem (or a similar one) that crashes Visual Studio, but I don't think I map anything from (or to) an object
type.
This is a really nasty behavior and it is hard to figure out what is going on.
My source and destination classes are huge, so I don't think I can share them.
Using version 3.5.0.
@DumboJetEngine can you share minimal reproducable classes?
I will try to. It appears that it happens when I map to and from properties like this one:
// Destination property :
public IReadOnlyList<EntryViewModel>? List { get; private set; }
// Source property :
public IReadOnlyList<Entry> List { get; private set; }
Probably, this is the only thing you need to add to your DTOs.
Using this mapper code was taking VS down entirely:
[Riok.Mapperly.Abstractions.Mapper]
public partial class MapperlyMapper
{
public partial MyViewModel MapDocument(MyEntity document);
}
Using this code seems to prevent VS from crashing, but I still get stack overflow exceptions in the build output, and weird VS behavior :
[Riok.Mapperly.Abstractions.Mapper(
UseDeepCloning = true,
PreferParameterlessConstructors = false,
AllowNullPropertyAssignment = true,
IncludedMembers = Riok.Mapperly.Abstractions.MemberVisibility.Private | Riok.Mapperly.Abstractions.MemberVisibility.Public | Riok.Mapperly.Abstractions.MemberVisibility.Protected,
ThrowOnPropertyMappingNullMismatch = true)]
public partial class MapperlyMapper
{
public partial MyViewModel MapDocument(MyEntity document);
}
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 'InsufficientExecutionStackException' with message 'Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.'.
System.InsufficientExecutionStackException: Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.
at System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack()
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
...
...
...
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode.ReplaceCore[TNode](IEnumerable`1 nodes, Func`3 computeReplacementNode, IEnumerable`1 tokens, Func`3 computeReplacementToken, IEnumerable`1 trivia, Func`3 computeReplacementTrivia)
at Microsoft.CodeAnalysis.SyntaxNodeExtensions.ReplaceToken[TRoot](TRoot root, SyntaxToken oldToken, SyntaxToken newToken)
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
...
...
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
at Riok.Mapperly.Descriptors.Mappings.ExistingTarget.NullDelegateExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax target) in /_/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs:line 22
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberExistingTargetMapping.Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberExistingTargetMapping.cs:line 21
at Riok.Mapperly.Descriptors.Mappings.MemberMappings.MemberAssignmentMappingContainer.<>c__DisplayClass4_0.<Build>b__1(IMemberAssignmentMapping m) in /_/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs:line 16
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Riok.Mapperly.Descriptors.Mappings.NewInstanceObjectMemberMethodMapping.BuildBody(TypeMappingBuildContext ctx)+MoveNext() in /_/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMethodMapping.cs:line 62
at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
at Riok.Mapperly.Descriptors.Mappings.MethodMapping.BuildMethod(SourceEmitterContext ctx) in /_/src/Riok.Mapperly/Descriptors/Mappings/MethodMapping.cs:line 96
at Riok.Mapperly.Emit.SourceEmitter.BuildMembers(SourceEmitterContext ctx, MapperDescriptor descriptor, CancellationToken cancellationToken)+MoveNext() in /_/src/Riok.Mapperly/Emit/SourceEmitter.cs:line 54
at Riok.Mapperly.Emit.Syntax.SyntaxIndentationExtensions.SeparateByLineFeed[TSyntax](IEnumerable`1 syntax, Int32 indentation)+MoveNext() in /_/src/Riok.Mapperly/Emit/Syntax/SyntaxIndentationExtensions.cs:line 30
at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
at Riok.Mapperly.Emit.SourceEmitter.Build(MapperDescriptor descriptor, CancellationToken cancellationToken) in /_/src/Riok.Mapperly/Emit/SourceEmitter.cs:line 22
at Riok.Mapperly.MapperGenerator.BuildDescriptor(CompilationContext compilationContext, MapperDeclaration mapperDeclaration, MapperConfiguration mapperDefaults, CancellationToken cancellationToken) in /_/src/Riok.Mapperly/MapperGenerator.cs:line 81
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)
@latonz I couldn't manage to reproduce the above problem in a stripped-down demo project, so I gave up. If you want, I could try to share some details via email.
Describe the bug
Using this example code, will make Visual Studio hang and crash as soon as you add the
Object? Item
property, or[Mapper]
attribute (I assume it is the source generator in some infinite loop or something):The mapper will probably not know what to do with a reference to type Object -- but it should not crash visual studio. Workaround is adding
private object? ObjectToObject(object? t) => t;
to the mapper so the generator knows what to do.Expected behavior Probably skipping the
Object? Item
property? Or just setting the reference as I do in my usecase.Environment (please complete the following information):