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.

Wed Mar 27, 2019 9:22 pm

In the attached document, I search for "Universal Pulseless Arrest". When I try to to GetAsOneRange(), I get an exception.

Code: Select all
                    TextSelection[] text = document.FindAllString("Universal Pulseless Arrest", false, true);
                    if (text == null)
                    {
                        continue;
                    }

                    foreach (TextSelection ts in text)
                    {
                        Debug.Print("Found text hit for " + textToMaps.Key);
                        TextRange tr = ts.GetAsOneRange();
                    }


Output:
Found text hit for Universal Pulseless Arrest
Found text hit for Universal Pulseless Arrest
Exception thrown: 'System.NullReferenceException' in Spire.Doc.dll
An unhandled exception of type 'System.NullReferenceException' occurred in Spire.Doc.dll
Object reference not set to an instance of an object.


On the command line:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Spire.Doc.Documents.TextSelection.GetAsOneRange(Boolean IsCopyFormat)
at Spire.Doc.Documents.TextSelection.GetAsOneRange()

owurman
 
Posts: 20
Joined: Tue Apr 04, 2017 8:43 pm

Wed Mar 27, 2019 10:19 pm

There's actually probably more to this. I think it has to do with a modification I made to the document earlier in my code. It is probably user error, so you can close this.

owurman
 
Posts: 20
Joined: Tue Apr 04, 2017 8:43 pm

Thu Mar 28, 2019 2:51 am

Hello,

Glad to hear that you found the reason for your issue. Any other question, just feel free to contact us.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc