I solved this intermittent and weird issue.
I realized that it occured
- only when selecting File > Preview Layouts and not Preview
- only on A/R invoice document type
So I checked the layouts for A/R invoices and found many Inactive ones that were obsolete, beyond the good ones. I deleted the obsolete layout and the error disappeared immediately!
I hope it could help someone else.