Quantcast
Channel: PDFsharp - A .NET library for processing PDF
Viewing all articles
Browse latest Browse all 46

Edited Issue: InvalidCastException in PdfAnnotations [15805]

$
0
0
PDFSharp 1.32
(Bug introduced in 1.31)
Previously reported at: http://forum.pdfsharp.net/viewtopic.php?f=3&t=1197

Attempting to iterate a PdfAnnotations instance with a foreach loop results in an InvalidCastException:

Unable to cast object of type 'AnnotationsIterator' to type 'System.Collections.Generic.IEnumerator`1[PdfSharp.Pdf.PdfItem]'
at PdfSharp.Pdf.Annotations.PdfAnnotations.GetEnumerator()

The private class AnnotationsIterator implements IEnumerator<PdfAnnotation>, but the GetEnumerator method attempts to cast it to IEnumerator<PdfItem>.

This would work if you were targeting 4.0, but in 2.0 generic covariance is not available.

To fix this, the AnnotationsIterator class needs to implement IEnumerator<PdfItem> instead of IEnumerator<PdfAnnotation>. The PdfAnnotations.GetEnumerator method will then work without the cast.
Comments: ** Comment from web user: ThomasHoevel **

Should be fixed with PDFsharp 1.50 beta 3.


Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>