From 6993c2c462144fa1316d01a122e93503555b9844 Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Tue, 28 Apr 2026 09:17:38 -0400 Subject: [PATCH] Fix invoice detail crash after first credit memo or refund is applied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/PowderCoating.Application/Mappings/InvoiceProfile.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PowderCoating.Application/Mappings/InvoiceProfile.cs b/src/PowderCoating.Application/Mappings/InvoiceProfile.cs index e18f687..8e1fe57 100644 --- a/src/PowderCoating.Application/Mappings/InvoiceProfile.cs +++ b/src/PowderCoating.Application/Mappings/InvoiceProfile.cs @@ -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()