You may encounter a memory leak, and a System.ComponentModel.Win32Exception exception may occur if you create several hundred XML Paper Specifications (XPS) in a Windows Presentation Foundation application
This article has been archived. It is offered "as is" and will no longer be updated.
If you create several hundred XML Paper Specifications (XPS) in one batch in a Microsoft Windows Presentation Foundation application, you may encounter a memory leak in the event handler. Additionally, a System.ComponentModel.Win32Exception exception may occur.
To work around this problem, preload the PresentationCore.dll file or the PresentationFramework.dll file in the primary application domain. Preload the file before the secondary application domain runs any Windows Presentation Foundation code. This operation adds the natively generated images into memory. Additionally, this operation prevents the problem.