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 **
(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.