FFImageLoading
FFImageLoading copied to clipboard
Unable to load svg image
🐛 Bug Report
Unable to load svg image. Here is the callstack
System.Collections.Generic.KeyNotFoundException: The given key 'offset' was not present in the dictionary.
at System.Collections.Generic.Dictionary2[TKey,TValue].get_Item (TKey key) [0x0001e] in <cbddc4225b2f45f09f3a1d43a1268bc0>:0 at FFImageLoading.Svg.Platform.SKSvg.ReadStops (System.Xml.Linq.XElement e) [0x0003e] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:1732 at FFImageLoading.Svg.Platform.SKSvg.ReadLinearGradient (System.Xml.Linq.XElement e) [0x00081] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:1668 at FFImageLoading.Svg.Platform.SKSvg.ReadPaints (System.Collections.Generic.Dictionary2[TKey,TValue] style, SkiaSharp.SKPaint& strokePaint, SkiaSharp.SKPaint& fillPaint, System.Boolean isGroup, System.String& fillId, S
ystem.String& strokeFillId) [0x0050e] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:1344
at FFImageLoading.Svg.Platform.SKSvg.ReadPaints (System.Xml.Linq.XElement e, SkiaSharp.SKPaint& stroke, SkiaSharp.SKPaint& fill, System.Boolean isGroup, System.Boolean isMask) [0x00008] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:1148
at FFImageLoading.Svg.Platform.SKSvg.ReadElement (System.Xml.Linq.XElement e, SkiaSharp.SKCanvas canvas, SkiaSharp.SKPaint stroke, SkiaSharp.SKPaint fill, System.Boolean isMask, System.Threading.CancellationToken token) [0x00048] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:237
at FFImageLoading.Svg.Platform.SKSvg.LoadElements (System.Collections.Generic.IEnumerable1[T] elements, SkiaSharp.SKCanvas canvas, SkiaSharp.SKPaint stroke, SkiaSharp.SKPaint fill, System.Threading.CancellationToken token) [0x00010] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:221 at FFImageLoading. Svg.Platform.SKSvg.Load (System.Xml.Linq.XDocument xdoc, System.Threading.CancellationToken token) [0x00417] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:209 at FFImageLoading.Svg.Platform.SKSvg.Load (System.Xml.XmlReader reader, System.Threading.CancellationToken token) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:100 at FFImageLoading.Svg.Platform.SKSvg.Load (System.IO.Stream stream, System.Threading.CancellationToken token) [0x00012] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SkSvg.cs:94 at FFImageLoading.Svg.Platform.SvgDataResolver.Resolve (System.String identifier, FFImageLoading.Work.TaskParameter parameters, System.Threading.CancellationToken token) [0x0019d] in C:\projects\ffimageloading\source\FFImageLoading.Svg.Shared\SvgDataResolver.cs:232 at FFImageLoading.DataResolvers.WrappedDataResolver.Resolve (System.String identifier, FFImageLoading.Work.TaskParameter parameters, System.Threading.CancellationToke n token) [0x0004e] in C:\projects\ffimageloading\source\FFImageLoading.Common\DataResolvers\WrappedDataResolver.cs:21 at FFImageLoading.Work.ImageLoaderTask3[TDecoderContainer,TImageContainer,TImageView].RunAsync () [0x0032d] in
SVG is attached
Expected behavior
Reproduction steps
Configuration
Version: 1.x
Platform:
-
[x] :iphone: iOS
-
[x] :robot: Android
-
[x] :monkey: Xamarin.Forms
I used https://jakearchibald.github.io/svgomg/ to see how the svg looks if we removed these lines from the SVG.
<stop offset=".54" stop-color="gray" stop-opacity=".12"/> <stop offset="1" stop-color="gray" stop-opacity=".1"/>
It may help anyone else if they are getting a similar error. I noticed that some of our SVGs were not working due to some specific svg formatting.
I know 21 days passed since you posted this and probably haven't thought about it since, but maybe it will help another person.
I used https://jakearchibald.github.io/svgomg/ to see how the svg looks if we removed these lines from the SVG.
<stop offset=".54" stop-color="gray" stop-opacity=".12"/> <stop offset="1" stop-color="gray" stop-opacity=".1"/>It may help anyone else if they are getting a similar error. I noticed that some of our SVGs were not working due to some specific svg formatting.I know 21 days passed since you posted this and probably haven't thought about it since, but maybe it will help another person.
While this solution didn't quite fix my issue, it did point me in the right direction. I have two SVGs that just don't want to display for some reason. I opened them up and the file structure is very different than the SVGs that are showing. Thanks for the direction!
I encountered this same issue recently and was pulling my hair out trying to figure out why FFImageLoading was telling me offset wasn't found in the dictionary. Turns out one of the stop elements in the svg file didn't have an offest property set. Once I added offset=0 to that element everything worked perfectly. The svg rendered fine in browsers so it wasn't clear immediately that FFImageLoading was trying to tell me I was missing a property.
Setting offset=0 to the first element in gradient helped indeed! Thanks