PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Tue Apr 29, 2025 5:43 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Mar 20, 2025 2:42 pm 
Offline

Joined: Thu Mar 20, 2025 1:53 pm
Posts: 1
I am creating a very simple 1 page Migradoc pdf. It has a simple header and body with one logo graphic. 99.5% of the time there is no problem but occasionally we get an exception originating from this line: pdfRenderer.RenderDocument()

This is running on a Windows 2016 Server as an API service in IIS. I am using version 6.1.1.

One other question -- in the exception it contains references to code on a d:\THHO... path. My server does not have a D: drive.

This is the full exception:

System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at MS.Win32.UnsafeNativeMethods.IInternetSecurityManager.MapUrlToZone(String pwszUrl, Int32& pdwZone, Int32 dwFlags)
at MS.Internal.SecurityHelper.MapUrlToZoneWrapper(Uri uri)
at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)
at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
at System.Windows.Media.Imaging.BitmapImage.EndInit()
at PdfSharp.Drawing.XImage.BitmapFromUri(Uri uri) in D:\THHO\Repos\PDFsharp\src\foundation\src\PDFsharp\src\PdfSharp\Drawing\XImage.cs:line 129
at PdfSharp.Drawing.XImage..ctor(String path) in D:\THHO\Repos\PDFsharp\src\foundation\src\PDFsharp\src\PdfSharp\Drawing\XImage.cs:line 172
at PdfSharp.Drawing.XImage.FromFile(String path) in D:\THHO\Repos\PDFsharp\src\foundation\src\PDFsharp\src\PdfSharp\Drawing\XImage.cs:line 274
at MigraDoc.Rendering.ImageRenderer.CalculateImageDimensions() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\ImageRenderer.cs:line 141
at MigraDoc.Rendering.ImageRenderer.Format(Area area, FormatInfo previousFormatInfo) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\ImageRenderer.cs:line 48
at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TopDownFormatter.cs:line 109
at MigraDoc.Rendering.FormattedCell.Format(XGraphics gfx) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedCell.cs:line 50
at MigraDoc.Rendering.TableRenderer.FormatCells() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TableRenderer.cs:line 379
at MigraDoc.Rendering.TableRenderer.InitFormat(Area area, FormatInfo previousFormatInfo) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TableRenderer.cs:line 350
at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TableRenderer.cs:line 397
at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TopDownFormatter.cs:line 109
at MigraDoc.Rendering.FormattedHeaderFooter.Format(XGraphics gfx) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedHeaderFooter.cs:line 26
at MigraDoc.Rendering.FormattedDocument.FormatHeader(HeaderFooterPosition hfp, HeaderFooter header) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedDocument.cs:line 138
at MigraDoc.Rendering.FormattedDocument.FormatHeadersFooters() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedDocument.cs:line 119
at MigraDoc.Rendering.FormattedDocument.MigraDoc.Rendering.IAreaProvider.GetNextArea() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedDocument.cs:line 383
at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\TopDownFormatter.cs:line 53
at MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\FormattedDocument.cs:line 87
at MigraDoc.Rendering.DocumentRenderer.PrepareDocument(RenderEvents renderEvents) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\DocumentRenderer.cs:line 46
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely) in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\PdfDocumentRenderer.cs:line 106
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\PdfDocumentRenderer.cs:line 135
at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument() in D:\THHO\Repos\PDFsharp\src\foundation\src\MigraDoc\src\MigraDoc.Rendering\Rendering\PdfDocumentRenderer.cs:line 127
at BusinessLogic.Helpers.AbsenceNoteHelper.<>c__DisplayClass3_0.<CreateAbsenceNote>b__0(String noteFilePath) in C:\BUILD_AND_PUBLISH\eMDAccess\Build\Solutions\eMDAccess\eMDAccessPrimary\Arc-Emd-Telemed\BusinessLogic\5_Helpers\AbsenceNoteHelper.cs:line 153


Attachments:
File comment: Here is an example of the pdf being created.
ExampleAbsenceNote.jpg
ExampleAbsenceNote.jpg [ 75.57 KiB | Viewed 850 times ]
Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 21, 2025 11:01 am 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 38
Maybe this is unrelated to your problem, but there was a potential DoS vulnerability disclosed not so long ago in the MapUrlToZone API.
(the top-most entry in your stack trace)
CVE: https://www.cve.org/CVERecord?id=CVE-2025-21276
Some details: https://windowsforum.com/threads/cve-20 ... ed.349591/
I'd check the IIS-logs and the Windows Event-Logs for unusual activity just to be sure.
I'd install the latest Windows-updates as well.

If that doesn't help, there are some strategies you could try.

- Implement retries (depending on your workflow this could be implemented server-side or client-side). Add delays between retries.
- Load images from streams instead of file-paths/urls (to bypass the affected API). This might not be possible if you have to load images from remote servers.
- While it may work most of the time, i would generally advice not to use client-APIs like GDI (or WPF in your case) in server-code. Try to switch from the WPF-build to the CORE-build of PDFsharp/MigraDoc.

As refactoring your app to use the CORE build of PDFsharp/MigraDoc could be non-trivial, i'd pick the low-hanging fruit first.

As to your second question:
The file-paths in the stack-trace (d:\THHO...) are stored in the debug-information of the assemblies (*.pdb-files).
They refer to paths on the machine where the assemblies were build, not to the machine they are executed on.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 21, 2025 12:17 pm 
Offline
User avatar

Joined: Thu Mar 06, 2025 10:43 am
Posts: 2
You are using the WPF build. In your case, WPF uses COM under the hood.

AFAIK the Core build does not use COM.
I don't know if the GDI build uses COM under the hood.

To avoid that COM error, trying the Core build is a safe approach. The Core build does not support all image formats supported by the WPF build, so some changes to your project may be necessary.
Trying the GDI build may work, but I'm not sure.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 22, 2025 10:07 am 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 38
Quote:
Trying the GDI build may work, but I'm not sure.
I'd strongly advice against using the GDI-build in an ASP.NET app as it is unsupported.
Quote from the documentation:
Quote:
Some types in the System.Drawing namespace rely on GDI+, which is not supported in Windows services and ASP.NET Core and ASP.NET apps. These types are in the System.Drawing.Common NuGet package and include System.Drawing.Bitmap and System.Drawing.Font. However, primitive types in the namespace, such as System.Drawing.Color, System.Drawing.Size, System.Drawing.Point, and System.Drawing.Rectangle, can be used in any application.
Source:
https://learn.microsoft.com/en-us/dotne ... .0#remarks

I couldn't find a similar official statement regarding WPF though.
All i could find is a blog-post which describes how to resize images in a web-app using WPF only to mention at the end:
Quote:
I contacted the WPF team to have the final word on whether this is supported. Unfortunately, it's not, and the documentation is being updated accordingly.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group