We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to fix error message: A first chance exception of type 'System.NullReferenceException' occurred in Aspose.Pdf.dll

Hi,

Environment: Aspose.PDF_10_3_0 and Aspose.PDF_10_9_0 versions.

I see an exception message: “A first chance exception of type ‘System.NullReferenceException’ occurred in Aspose.Pdf.dll” when I try to extract adobe fields using following code for the attached test document. Here is my code:


Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filename);

Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(pdfDocument);

//get all field names
String[] allfields = form.FieldNames;

Aspose.Pdf.PageCollection pageCollection = pdfDocument.Pages;

Aspose.Pdf.InteractiveFeatures.Forms.FormType formType = pdfDocument.Form.Type;
string fieldFullName = “”;
Aspose.Pdf.Facades.FormFieldFacade fieldfacade = null;



foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in pdfDocument.Form.Fields)
{
fieldFullName = formField.FullName;
try
{
fieldfacade = form.GetFieldFacade(fieldFullName); // GIVES EXCEPTION AT THIS LINE

}catch (Exception e){

Trace.Write(e.Message);
}
}
1. How can I handle this error?
2. What is a work around for this?

Thank you,
Sireesha

Hi Sireesha,


Thanks
for using our API’s.
<o:p></o:p>

I
have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this problem as PDFNEWNET-39540 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.

I also have this error :frowning:

Hi Birgit,


Thanks for your inquiry. Please note usually issue varies from file to file, so please share your sample document here, we will look into it and will provide you information accordingly.

We are sorry for the inconvenience.

Best Regards,

I’ve just seen your reply. Did you already find a solution? See attached the document which produces the exception.

Thanks,
Birgit

Hi Birgit,


Thanks for sharing your sample document. I have tested the scenario using Aspose.Pdf for .NET 11.1.0 and unable to notice any exception. Please download and try latest version of Aspose.Pdf for .NET, it will resolve the issue. However if the issue persist then please share your sample code here, we will look into it and guide you.

Aspose.Pdf.Document
pdfDocument = new Aspose.Pdf.Document(@“C:\Users\Home\Downloads\ErhbgsBogStammdatenStromVersorgerId8674doc.pdf”);<o:p></o:p>

Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(pdfDocument);

//get all field names

String[] allfields = form.FieldNames;

Aspose.Pdf.PageCollection pageCollection = pdfDocument.Pages;

Aspose.Pdf.InteractiveFeatures.Forms.FormType formType = pdfDocument.Form.Type;

string fieldFullName = "";

Aspose.Pdf.Facades.FormFieldFacade fieldfacade = null;

foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in pdfDocument.Form.Fields)

{

fieldFullName = formField.FullName;

try

{

fieldfacade = form.GetFieldFacade(fieldFullName); // GIVES EXCEPTION AT THIS LINE

//pdfForm.FillField(fieldFullName, "44.name_vorname");

Console.WriteLine("field FullName: {0} page: {1}",formField.FullName, fieldfacade.PageNumber);

}

catch (Exception ex)

{

Trace.Write(ex.Message);

}

}

Please feel free to contact us for any further assistance.


Best Regards,