I’m looking for a way to handle this either via a global Mapperly configuration or a mapper-level configuration, without having to make widespread nullable changes across the domain and DTO models.
For context, here’s a simple example:
public partial class HrCountryWithNavigationPropertiesToDtoMapper
: MapperBase<HrCountryWithNavigationProperties, HrCountryWithNavigationPropertiesDto>
{
public override partial HrCountryWithNavigationPropertiesDto Map(HrCountryWithNavigationProperties source);
public override partial void Map(HrCountryWithNavigationProperties source, HrCountryWithNavigationPropertiesDto destination);
}
public class HrCountryWithNavigationProperties
{
public HrCountry HrCountry { get; set; }
public HrMailCountry HrMailCountry { get; set; }
}
public class HrCountryWithNavigationPropertiesDto
{
public HrCountryDto HrCountry { get; set; }
public HrMailCountryDto HrMailCountry { get; set; }
}
During runtime, if HrMailCountry (or any navigation property) is null, Mapperly throws a NullReferenceException. This differs from AutoMapper’s behavior, where null navigation properties were implicitly ignored or mapped to default values. Making these properties nullable (HrMailCountry?, HrMailCountryDto?) resolves the issue, but that would require extensive refactoring across the solution, which I’d like to avoid if possible.
System.NullReferenceException: 'Object reference not set to an instance of an object.' source was null.I didn't find this fix in the ABP documentation anywhere. Could you please share the documentation here so that I can have a look. Thanks!
Hi, I've shared the application code for one of the module with you. Please have a look. It's a production app, not a test app, so I cannot share the whole source code with you. Thanks!
I can give you the remote access of my system, let me know when you're comfortable to connect Thanks!
Yes, it's already configured
[DependsOn(
typeof(IseCoreDomainModule),
typeof(IseCoreApplicationContractsModule),
typeof(AbpDddApplicationModule),
typeof(AbpMapperlyModule)
)]
public class IseCoreApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddMapperlyObjectMapper<IseCoreApplicationModule>();
}
}
Trying to do: var filter = ObjectMapper.Map<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>(input); but getting error.
Here is the configuration for mapperly in file IseCoreApplicationMappers.cs
[Mapper]
public partial class HrMissionaryLookupRequestDtoToHrMissionaryLookupFilterMapper
: MapperBase<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>
{
public override partial HrMissionaryLookupFilter Map(HrMissionaryLookupRequestDto source);
public override partial void Map(
HrMissionaryLookupRequestDto source,
HrMissionaryLookupFilter destination
);
}
Issue: AutoMapperMappingException after migrating from AutoMapper to Mapperly in ABP (.NET 9 → .NET 10)
Exception message and stack trace
AutoMapper.AutoMapperMappingException
HResult=0x80131500
Message=Missing type map configuration or unsupported mapping.
Source=AutoMapper
StackTrace: <Cannot evaluate the exception stack trace>
Steps to reproduce
Observed behavior
ObjectMapper.Map<TSource, TDestination>(), I get the AutoMapperMappingException shown above.Expected behavior
ObjectMapper.Map (ABP’s abstraction) instead of injecting individual Mapperly mapper classes everywhere.Question
ObjectMapper.Map works as expected in ABP?ObjectMapper resolve Mapperly-based mappers instead of falling back to AutoMapper?