Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCastException upon Open #2

Closed
nezbo opened this issue Jun 28, 2017 · 6 comments
Closed

InvalidCastException upon Open #2

nezbo opened this issue Jun 28, 2017 · 6 comments

Comments

@nezbo
Copy link

nezbo commented Jun 28, 2017

Hi there. I am trying to get the pdf parsing working in a .NET Core application, but receive this exception immediately upon trying to open the pdf:

exception	{System.InvalidCastException: Unable to cast object of type 'PdfSharpCore.Pdf.PdfInteger' to type 'System.IConvertible'.
   at System.Convert.ToInt32(Object value)
   at PdfSharpCore.Pdf.IO.Parser.GetStreamLength(PdfDictionary dict)
   at PdfSharpCore.Pdf.IO.Parser.ReadObject(PdfObject pdfObject, PdfObjectID objectID, Boolean includeReferences, Boolean fromObjecStream)
   at PdfSharpCore.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider passwordProvider)
   at PdfSharpCore.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openmode)
   at PdfSharpCore.Pdf.IO.PdfReader.Open(Stream stream, PdfDocumentOpenMode openmode)

The code is simply this at the moment:

            Stream stream = File.OpenRead(path);
            PdfDocument book = PdfReader.Open(stream, PdfDocumentOpenMode.ReadOnly);
            Console.WriteLine(string.Format("\tPageCount = {0}", book.PageCount));

where it fails on the second one. Any suggestions on how to fix the issue?

I have tested with this pdf (placed in local filesystem)

@ststeiger
Copy link
Owner

Do you get this error as well if you do that with non-CORE PdfSharp ?
e.g. try with PdfSharp for .NET 4 or .NET 2.0
If yes, that's a PdfSharp bug.
I got this error/similar-error before on normal versions of PdfSharp.

@gvamsilatha
Copy link

I tried with .net standard project using PdfSharp, i am able to open the pdf document. looks like PdfSharpcore has issue with opening the pdf , it gives the below error 'Unable to cast object of type 'PdfSharpCore.Pdf.PdfInteger' to type 'System.IConvertible'.'

@ststeiger
Copy link
Owner

The issue has already been fixed.
Maybe clone the latest version.

@gvamsilatha
Copy link

thanks for your quick response. Actually I am referencing the latest version of PdfSharpCore version 1.0.1 of nuget package.
now I tried to clone the project, but couldnot load the projects in the soluciton file , I think because of CoreDb.shproj is not available when I clone. none of the projects were loaded in the solution file.
image

@startnow65
Copy link
Contributor

startnow65 commented Jun 11, 2018

Hi gvamsilatha,

I have updated the Nuget Package with the latest fixes. You can add the Nuget package to your project and test.

@gvamsilatha
Copy link

awesome. thanks a lot. its not throwing error now. I can play around with it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants