question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem trying to render SVG objects (Open() method)

See original GitHub issue

Description

In a C# project I’m trying to convert from SVG to Image object using the following code: img = Svg.SvgDocument.Open(filePath).Draw();

The problem is with the ‘Open’ method since I divided that line into Open first and Draw after it.

And it does not fail but the svg is not being rendered correctly. I also have these traceback errors: HCTgui.exe Warning: 0 : Attribute ‘width’ cannot be set - type ‘Svg.SvgDocument’ cannot convert from string ‘29.724014mm’. HCTgui.exe Warning: 0 : Attribute ‘height’ cannot be set - type ‘Svg.SvgDocument’ cannot convert from string ‘16.038712mm’. HCTgui.exe Warning: 0 : Attribute ‘transform’ cannot be set - type ‘Svg.SvgGroup’ cannot convert from string ‘translate(-60.535697,-122.57997)’. HCTgui.exe Warning: 0 : Attribute ‘transform’ cannot be set - type ‘Svg.SvgGroup’ cannot convert from string ‘matrix(4.5495881,0,0,3.9014996,-235.85594,-137.43323)’. HCTgui.exe Warning: 0 : Attribute ‘transform’ cannot be set - type ‘Svg.SvgGroup’ cannot convert from string ‘matrix(0.22003619,0,0,-0.25571455,52.118913,92.951338)’. HCTgui.exe Warning: 0 : Attribute ‘transform’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘matrix(0,-1,-1,0,0,0)’. HCTgui.exe Warning: 0 : Attribute ‘d’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘m -86.822733,-59.964423 a 6.3617005,14.09141 0 0 1 -5.577324,-6.972381 6.3617005,14.09141 0 0 1 -0.01308,-14.185706 6.3617005,14.09141 0 0 1 5.564423,-7.022775’. HCTgui.exe Warning: 0 : Attribute ‘transform’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘rotate(90)’. HCTgui.exe Warning: 0 : Attribute ‘d’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘m 102.85328,-59.964423 a 6.3617005,14.09141 0 0 1 -5.57732,-6.972381 6.3617005,14.09141 0 0 1 -0.01308,-14.185706 6.3617005,14.09141 0 0 1 5.564427,-7.022775’. HCTgui.exe Warning: 0 : Attribute ‘stroke-width’ cannot be set - type ‘Svg.SvgGroup’ cannot convert from string ‘2.470398’. HCTgui.exe Warning: 0 : Attribute ‘stroke-dasharray’ cannot be set - type ‘Svg.SvgGroup’ cannot convert from string ‘none’. HCTgui.exe Warning: 0 : Attribute ‘stroke-width’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘1.509307’. HCTgui.exe Warning: 0 : Attribute ‘stroke-dasharray’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘none’. HCTgui.exe Warning: 0 : Attribute ‘stroke-dashoffset’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘3.779527’. HCTgui.exe Warning: 0 : Attribute ‘stroke-width’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘1.509307’. HCTgui.exe Warning: 0 : Attribute ‘stroke-dasharray’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘none’. HCTgui.exe Warning: 0 : Attribute ‘stroke-dashoffset’ cannot be set - type ‘Svg.SvgPath’ cannot convert from string ‘3.779527’.

Example data

It happens with any single .SVG I try to use. All of them correctly validated and working.

Used Versions

I’m using Visual Studio 2019 Pro, Windows 10 and SVG 3.3.0

Thank you so much!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RolandJosurancommented, Oct 30, 2021

Thank you very much! I’m not very experienced in using Visual Studio. It’s quite possible that the error is caused by an environment issue. I have run the SVGViewer from GitHub in a separate .net 5.0 solution, where everything worked well. The error occurred in a .NET Framework 4.8 project where the SVG.net DLL from NuGet is referenced. I’m not familiar enough with Visual Studio to assess, if this could be a reason or how to test it.

I will try to find out more…

  • Ok, I also found a “manifest definition does not match the Assembly reference” error. I hate errors like that, as they are very confusing. I try this solution. --> No
  • <package> targetFramework of SVG is net48. Cannot set it to net5.0 --> No

Edit: Quit sure, that this is an execution environment issue. It works with every new project I tried, but not in my actual solution. So thank you for your time and investigations. I have to find the bug by myself.

1reaction
H1Gdevcommented, Oct 29, 2021

I created the following simple console app and get SVG.NET library from NuGet.

using System.IO;
using Svg;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var rootPath = @"<PATH_TO_ROOT_DIRECTORY>";
            var svgPath = Path.Combine(rootPath, "Image.svg");
            var imagePath = Path.Combine(rootPath, "Image.png");
            using (var image = SvgDocument.Open(svgPath).Draw())
            {
                image.Save(imagePath);
            }
        }
    }
}

Result was output correctly. (3.3.0 - 3.2.1).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome not rendering SVG referenced via <img> element
On problems try to open the images first with a program that is capable to read svg-images. If that fails, then the svg-image...
Read more >
Here's How I Solved a Weird Bug Using Tried and True ...
Isolating the issue. Our next hypothesis states that Safari has a bug when rendering SVG inside an HTML <button > element. Since the...
Read more >
How to use SVGs in React
Learn how to use or render an SVG image on a React webpage, the pros and cons, and using components like and ....
Read more >
How to use SVGs in React
This article will explore how to use SVG in React in three examples.
Read more >
Things you need to know about working with SVG in VS ...
SVG is markup and VS Code treats SVG files like XML, which is only text. You would need XSLT to render it into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found