Fix invoice detail crash after first credit memo or refund is applied

AutoMapper 12+ throws AutoMapperMappingException when mapping a non-empty
collection for which no element type map is registered. Invoice.CreditApplications
and Invoice.Refunds had no CreateMap entries, so the invoice Details view worked
fine until the first credit or refund existed — at that point AutoMapper tried
to map the element type and threw, causing the catch block to redirect to the
invoice list with a generic "failed to load" error.

Fix: mark CreditApplications and Refunds as Ignore() in the Invoice->InvoiceDto
AutoMapper profile. Both collections are already built manually in
BuildInvoiceDtoAsync, matching the existing GiftCertificateRedemptions pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-28 09:17:38 -04:00
parent 1cb7a8ca4a
commit 6993c2c462
@@ -33,6 +33,10 @@ public class InvoiceProfile : Profile
.ForMember(d => d.BalanceDue, o => o.MapFrom(s => s.BalanceDue))
.ForMember(d => d.SalesTaxAccountName, o => o.MapFrom(s => s.SalesTaxAccount != null
? $"{s.SalesTaxAccount.AccountNumber} {s.SalesTaxAccount.Name}" : null))
// These three collections are built manually in BuildInvoiceDtoAsync — no AutoMapper element map exists.
// AutoMapper 12+ throws for non-empty collections with no registered element mapping, so Ignore here.
.ForMember(d => d.Refunds, o => o.Ignore())
.ForMember(d => d.CreditApplications, o => o.Ignore())
.ForMember(d => d.GiftCertificateRedemptions, o => o.Ignore());
CreateMap<InvoiceItem, InvoiceItemDto>()