-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Describe the bug
When starting my application a System.TypeInitializationException is thrown at the following call stack:
DotNetProjects.SVGImage!SVGImage.SVG.Shapes.Shape.GetTextStyle(svg) Line 512 C#
DotNetProjects.SVGImage!SVGImage.SVG.Shapes.Shape.Shape(svg, node, parent) Line 66 C#
DotNetProjects.SVGImage!SVGImage.SVG.Shapes.Shape.Shape(svg, node) Line 43 C#
DotNetProjects.SVGImage!SVGImage.SVG.Shapes.Group.Group(svg, node, parent) Line 14 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVG.Parse(node) Line 331 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVG.Load(svgDocument) Line 267 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVG.Load(stream) Line 220 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVG.SVG(stream, externalFileLoader) Line 65 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVGRender.LoadDrawing(stream) Line 112 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVGImage.SetImage.AnonymousMethod__0(render) Line 304 C#
DotNetProjects.SVGImage!SVGImage.SVG.SVGImage.OnInitialized(e) Line 380 C#
The inner exception is an ArgumentException coming from the Dictionary class saying that "An element with the same key has already been added". This is thrown at the following location:
SVGImage.SVG.Utils.FontResolver.FontResolver(int) in FontResolver.cs
SVGImage.SVG.TextStyle.TextStyle() in TextStyle.cs
I debugged this and found out that the source of the exception is the normalization of font names in the FontResolver constructor. All available fonts are added to a dictionary using "normalized" font names as the key. Normalization here means that whitespace, dashes and underscores are removed and the result is converted to lower case.
However, on my system I have two installed fonts with similar names: "Guttman Aharoni" and "Guttman-Aharoni". When normalizing these font names, they will be using the same key for the dictionary, which causes the exception. No idea where these fonts are coming from, they were installed by default. Anyway, similar cases like this could happen anytime and should be expected. What makes it even worse: The bug only occurs on systems with problematic font combinations, so it may not be found on a test system and only fail on a customer system!
I attached both fonts to this ticket as a ZIP file.
To Reproduce
Steps to reproduce the behavior:
- Install the attached fonts in your system
- Run an application using an SVGImage
- Open the location in the application where this SVGImage is used, so that it will be initialized
- Exception occurs
Expected behavior
No exception should be thrown.
Screenshots
Screenshots not available since app does not start.
Additional context
None