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..71b3661303 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 object mapping was found for the specified source and destination types." + + newLine + + newLine + + "Mapping attempted:" + + newLine + + $"{typeof(TSource).Name} -> {typeof(TDestination).Name}" + + newLine + + $"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" + + newLine + + newLine + + "How to fix:" + + newLine + + "Define a mapping class for these types:" + + newLine + + " - Use MapperBase for one-way mapping." + + newLine + + " - Use TwoWayMapperBase for two-way mapping." + + newLine + + newLine + + "For details, see the Mapperly integration document 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) diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs index 3f0773f0a1..b5987769be 100644 --- a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs @@ -106,9 +106,14 @@ public class AbpMapperlyModule_Basic_Tests : AbpIntegratedTest(() =>_objectMapper.Map(new MyEntity())); - exception.Message.ShouldBe("No " + - "Volo.Abp.Mapperly.IAbpMapperlyMapper or " + - "Volo.Abp.Mapperly.IAbpReverseMapperlyMapper" + - " was found"); + exception.Message.ShouldBe("No object mapping was found for the specified source and destination types.\n\n" + + "Mapping attempted:\n" + + "MyEntity -> MyClassDto\n" + + "Volo.Abp.Mapperly.SampleClasses.MyEntity -> Volo.Abp.Mapperly.MyClassDto\n\n" + + "How to fix:\n" + + "Define a mapping class for these types:" + "\n" + + " - Use MapperBase for one-way mapping.\n" + + " - Use TwoWayMapperBase for two-way mapping.\n\n" + + "For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"); } }