Very strange issue here and I'm stumped.
To start, I'm taking a LocalReport and rendering with a slightly modified version of this:This
Once I have the rendered pages, I provide the streams to a PrintDocument. It has a PrintPage handler that creates a Metafile with the page stream and draws the metafile content onto the PrintPageEventArgs Graphics.
Here's the PrintPage:
if (stream.Length > 0) { stream.Position = 0; using (var pageImage = new Metafile(stream)) { ev.Graphics.DrawImage(pageImage, ev.PageBounds); } stream.Close(); stream.Dispose(); GC.Collect(); }
I was having a problem with getting a generic GDI exception, but it only seemed to be if I was printing a large enough report and if it was being printed from a Windows XP machine.
My thought was that the metafile wasn't getting disposed properly. What I decided to do was put the following in a loop:
for ( loop = 0; loop < 100; loop++) { stream.Position = 0; using (var pageImage = new Metafile(stream)) { ev.Graphics.DrawImage(pageImage, ev.PageBounds); } }
Here are my observations:
1. Windows XP: Same problem as before, generic GDI crash. Also note that I tested this with a small version of the report that normally would have rendered fine.
2. Windows 7: Doesn't crash, but renders strange. The report has a photo in the middle of the first page. It seems to have taken this photo and shrunk it down to about half the size and layered it on top of the correct sized photo. It seemed like the rest of the report rendered fine.
I'm not really worried about the Windows 7 issue since it renders fine normally. I'm just wondering what I'm supposed to do about the Windows XP problem. Upgrading the XP machine to 7 is an option, but I was hoping to actually fix the issue. My gut feeling says it's an issue with not disposing properly, but I don't know what to do.
I thought it was related to This, but we seem to have the latest copy of the file.