Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Feb 05, 2024 10:34 am

Hello guys,

the following snippet works fine until 11.11.8:

Code: Select all
var document = new Document("MyTestDocument.docx");
document.Replace(pattern: "{(?i)\[\[Event_Date.*\]\]}", replace: "02/05/2024");

But it fails from 11.12.2 (and all newer versions including 12.2.11): System.NullReferenceException when executing document.Replace().

For testing:
Create an empty Word document, type "[[Event_Date]]" and save the file as "MyTestDocument.docx". The run the code above.

In 11.11.8, the placeholder [[Event_Date]] is replaced by "02/05/2024". From 11.12.2 on something must have changed because the code breaks with a NullReferenceException.

Did you change somehthing on purpose or is this a bug?

Thanks
Ingmar

softwarea
 
Posts: 8
Joined: Sun Apr 17, 2016 1:59 pm

Tue Feb 06, 2024 2:32 am

Hello,

Thank you for your inquiry.
I tested your code using Spire.Doc version 11.11.8 and Spire.Doc version 12.2.11, but neither of the resulting files displayed the replaced text correctly. After I modified your code and tested it using Spire.Doc version 12.2.11, the result file was correct and the program did not report any errors. I am attaching my test code and the result file for your reference. Please test again using my code.
If the issue still exists after testing, please provide the following information for further investigation. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
1) Your input Word file.
2) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
3) Your application type, such as Console app (. Net 6.0).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc