I have an issue converting the attached document from *.docx to *.pdf format.
There is an exception:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Aspose.Words
There is the same issue with calling the method UpdatePageLayout().
Code sample:
var doc = new Document(inputFile);
doc.Save(outputFile, SaveFormat.Pdf);
I use Aspose.Words.dll 25.2.0.0.
test35.zip (635.3 KB)
@licenses
It seems you are encountering a NullReferenceException
while trying to convert a DOCX document to PDF using Aspose.Words. This type of exception typically occurs when the code attempts to access an object that has not been initialized.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
-
Check the Document: Ensure that the DOCX file you are trying to convert is not corrupted. You can try opening it in Microsoft Word to verify that it opens without any issues.
-
Update Aspose.Words: You are using version 25.2.0.0 of Aspose.Words. Consider updating to the latest version, as there may have been bug fixes or improvements that address this issue.
-
Use a Stream: Instead of directly loading the document from a file path, try loading it from a stream. This can sometimes help with issues related to file access. Here’s an example of how to do this:
using (FileStream stream = new FileStream(inputFile, FileMode.Open))
{
Document doc = new Document(stream);
doc.Save(outputFile, SaveFormat.Pdf);
}
-
Check for Updates: If you are calling UpdatePageLayout()
, ensure that the document is fully loaded and that there are no issues with the document structure before calling this method.
-
Error Handling: Implement error handling to catch exceptions and log more details about the state of your application when the error occurs. This can help you identify what might be causing the NullReferenceException
.
If the problem persists after trying these steps, consider reaching out to Aspose support with the specific document that is causing the issue, as they may be able to provide more targeted assistance.
If you have any further questions or need additional help, feel free to ask!
@licenses
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-27935
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as WORDSNET-27935) have been fixed in this Aspose.Words for .NET 25.4 update also available on NuGet.