diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs index 80f959710d..b2c0d6275f 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectMapping; -using Volo.Abp.Reflection; namespace Volo.Abp.Mapperly; @@ -62,8 +61,7 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider return destination; } - throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper))} or" + - $" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper))} was found"); + throw GetNoMapperFoundException(); } public virtual TDestination Map(TSource source, TDestination destination) @@ -95,8 +93,34 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider return destination; } - throw new AbpException($"No {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpMapperlyMapper))} or" + - $" {TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(IAbpReverseMapperlyMapper))} was found"); + throw GetNoMapperFoundException(); + } + + protected virtual AbpException GetNoMapperFoundException() + { + var newLine = Environment.NewLine; + var message = "No type mapper class was found for the given source and destination types." + + newLine + + newLine + + "Mapping types:" + + newLine + + $"{typeof(TSource).Name} -> {typeof(TDestination).Name}" + + newLine + + $"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" + + newLine + + newLine + + "Define a mapping class to resolve this issue:" + + newLine + + " - Use MapperBase for one-way mapping." + + newLine + + " - Use TwoWayMapperBase for two-way mapping." + + newLine + + newLine + + "See the Mapperly documentation for details:" + + newLine + + "https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"; + + return new AbpException(message); } protected virtual bool TryToMapCollection(TSource source, TDestination? destination, out TDestination collectionResult)