Prerequisites
ImageSharp version
3.1.4
Other ImageSharp packages and versions
SixLabors.Drawing 2.1.3, SixLabors.Fonts 2.0.3
Environment (Operating system, version and so on)
Windows 10 pro 22H2, 48g ddr4, i7 13700, gtx 650 ti boost
.NET Framework version
.NET 8.0.2
Description
By default, a new instance of RichTextOptions do not initialize property TextRuns with IReadOnlyList (though base TextOptions initialize it with Array.Empty()), so if any code tries to access TextRuns property of a just newly created instance of RichTextOptions, it throws an InvalidCastException
Steps to Reproduce
FontFamily fontFamily = SystemFonts.Collection.Families.First();
Font font = fontFamily.CreateFont(69); // just an example font, as font is required to construct a richTextOptions
TextOptions textOptions = new(font);
Console.WriteLine(string.Join(',', textOptions.TextRuns)); // ok
RichTextOptions richTextOptions = new(font);
try
{
Console.WriteLine(string.Join(',', richTextOptions.TextRuns)); // fault
}
catch (Exception ex)
{
Console.WriteLine(ex);
//System.InvalidCastException: Unable to cast object of type 'SixLabors.Fonts.TextRun[]' to type 'System.Collections.Generic.IReadOnlyList`1[SixLabors.ImageSharp.Drawing.Processing.RichTextRun]'.
// at SixLabors.ImageSharp.Drawing.Processing.RichTextOptions.get_TextRuns()
}
richTextOptions.TextRuns = Array.Empty<RichTextRun>(); // ok
Console.WriteLine(string.Join(',', richTextOptions.TextRuns)); // ok
Images
No response
Prerequisites
DEBUGandRELEASEmodeImageSharp version
3.1.4
Other ImageSharp packages and versions
SixLabors.Drawing 2.1.3, SixLabors.Fonts 2.0.3
Environment (Operating system, version and so on)
Windows 10 pro 22H2, 48g ddr4, i7 13700, gtx 650 ti boost
.NET Framework version
.NET 8.0.2
Description
By default, a new instance of
RichTextOptionsdo not initialize propertyTextRunswith IReadOnlyList (though baseTextOptionsinitialize it with Array.Empty()), so if any code tries to access TextRuns property of a just newly created instance of RichTextOptions, it throws an InvalidCastExceptionSteps to Reproduce
Images
No response