Hello,
We have come across a NullReferenceException when calling Portion.GetRect in Aspose.Slides.NET 25.10.0.
I’ve have attached a minimal example
null_ref_exception.zip (520.2 KB)
var pres = new Presentation("./null_ref_exception.pptx");
var slide = pres.Slides[0];
var shape = (AutoShape)slide.Shapes[0];
var portion = shape.TextFrame.Paragraphs[0].Portions[0];
var rect = portion.GetRect(); // null ref here
Thanks for your attention.
Kind Regards,
Draftable Team
@draftable
The NullReferenceException you are encountering when calling Portion.GetRect() may occur if the Portion object is not properly initialized or if it does not contain any text. Here are a few steps to troubleshoot and resolve the issue:
-
Check if the Portion is Null: Before calling GetRect(), ensure that the portion object is not null. You can add a check like this:
if (portion != null)
{
var rect = portion.GetRect();
}
else
{
Console.WriteLine("The portion is null.");
}
-
Verify Text Content: Ensure that the TextFrame and its Paragraphs and Portions actually contain text. If the shape does not have any text, the Portion will be null.
-
Debugging: You can print out the number of paragraphs and portions to see if they are being populated correctly:
Console.WriteLine($"Paragraphs count: {shape.TextFrame.Paragraphs.Count}");
if (shape.TextFrame.Paragraphs.Count > 0)
{
Console.WriteLine($"Portions count: {shape.TextFrame.Paragraphs[0].Portions.Count}");
}
If the issue persists after these checks, consider providing more details about the content of the pptx file or any specific conditions that might lead to the NullReferenceException.
For further assistance, consult the official documentation or community forums for similar issues and solutions.
The portion object is non-null and does contain text. The null reference exception occurs within the GetRect call. Here is the obfuscated stack trace
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Slides .(String , , , Boolean , Int32 , & )
at Aspose.Slides .(String , , Boolean )
at Aspose.Slides. .( , , Boolean )
at Aspose.Slides. .()
at Aspose.Slides. .(Portion , Boolean)
at Aspose.Slides. .thpfuzq4zm7ebde387evad53w75tjfpj (Portion , Boolean)
at Aspose.Slides. .a9lup2m6j9fts8rt7duac8r6xb7gg25f (Boolean )
at Aspose.Slides.Portion.GetRect()
at Scratch.Program.Main(String[] args)
@draftable,
Thank you for contacting free support. I am working on the issue and will get back to you soon.
@draftable,
I have reproduced the NullReferenceException you described.
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): SLIDESNET-45170
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.
1 Like