Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for .NET Core #400

Closed
legas1 opened this issue Jan 9, 2019 · 37 comments
Closed

Support for .NET Core #400

legas1 opened this issue Jan 9, 2019 · 37 comments

Comments

@legas1
Copy link

legas1 commented Jan 9, 2019

Hello, I want to thank you for this awesome lib. However when I deal with .svgs from Adobe Illustrator (not sure which version, because graphics man...) I got bunch of errors like:
The CreateDocument method can only be used to parse root <svg> elements. or Stack empty.

I use SVG 2.4.0, NetCore 2.1.

SVG sample here: https://pastebin.com/jsfeRi1y
Code I use is just simple open and after this the errors happen: SvgDocument svgDocument = SvgDocument.Open(file);

Edit: maybe it can be fixed by merging #326.

@mrbean-bremen
Copy link
Member

Currently, .NET Core is not supported - see also #248.
Ok - just saw your edit - you are right, #326 may fix this. You may actually try it locally to check if it helps with your issues.

@mrbean-bremen mrbean-bremen changed the title Errors upon opening SVGs from AI Support for .NET Core Feb 9, 2019
@mrbean-bremen
Copy link
Member

I adapted the issue title to clarify what this is about. Note that there is a new PR (#415) that specifically adds support for .NET Core 2.2, so that may work for you.

@legas1
Copy link
Author

legas1 commented Feb 9, 2019

I'll check it out later, thank you.

@laci84
Copy link

laci84 commented Feb 27, 2019

please some workaround or merge pull request to support .net core

@mrbean-bremen
Copy link
Member

The committer wanted to make some changes I'm waiting for, and we are also waiting for @tebjan for clarification regarding VS version - so I can't give you a definitive date for when this will be merged...

@tebjan
Copy link
Contributor

tebjan commented Feb 27, 2019

i'd say VS2017 is fine. if it all works with VS2015, even better. but i think .net core and standard have much better support in 2017.

@mrbean-bremen
Copy link
Member

Ok, thanks! So merging the PR which requires VS2017 would be fine (once it is finished)?

@mrbean-bremen
Copy link
Member

@tebjan - I think it would make sense to make another minor release before that, just in case - there have been a few fixes since the last release.

@laci84
Copy link

laci84 commented Mar 1, 2019

when can i except that release with .net core support?
thx!

@tebjan
Copy link
Contributor

tebjan commented Mar 1, 2019

@mrbean-bremen sure thing, i'll upload a new nuget. EDIT: new nuget is up!

@mrbean-bremen
Copy link
Member

@Noah1911 - it has been some time; if you are still interested, could you please check with current master?

@legas1
Copy link
Author

legas1 commented May 13, 2019

@mrbean-bremen - yes I'm still interested. I still don't have time to test it, but it looks promising. I try to test it at the end of this week.

@nrbalda
Copy link

nrbalda commented May 16, 2019

Hey I'm going to chime in here since I had the same problems with .NET core 2.1. This morning I updated everything to .NET core 2.2 and cloned master. I popped the dll in there with a local reference and suddenly all my SVGs started rendering.

I'm using an SVG template that I dynamically inject some values into before I go through a few conversions. The conversion chain was SVG template > XmlDoc > SVGDocument > Bitmap > ByteArray(PNG) > Base64 String.

I'm returing that Base64 string as a data URI for an image's source tag, and that image lives in an HTML div. Everything renders nicely now.

Before I was using SVG 2.4.3 and all of my images were just rendering as either a white box (PNG) or a black box (GIF/JPEG).

Thanks for the update.

@jackmott
Copy link

Am I interpreting that thread correctly, it looks like the next nuget package release will support .NET Core? Since master source does currently?
Just wondering if I should bother cloning and building myself or just wait a few days. Any help needed with testing?

@mrbean-bremen
Copy link
Member

Yes, you are right. Any tests are welcome, especially on non-Windows systems.
I'm not sure about the release date, I would have been given it some time to be tested, though an early release with some bugfix release later might also be ok.
@tebjan - what do you think?

@chucker
Copy link
Contributor

chucker commented May 26, 2019

@jackmott it’d be particularly helpful for someone to test on Linux, since I believe nobody has.

@jackmott
Copy link

i should be able to help with that monday night when i get home

This was referenced May 28, 2019
@mrtristan
Copy link

@tebjan it seems this is geared to you: to make testing easier i'd advocate for releasing "preview" flavors of nuget packages so you can control the installation process and ensure there's no issues with the variability in people compiling and dropping dlls and such as it seems is needed at the moment to test.

@tebjan
Copy link
Contributor

tebjan commented Jun 6, 2019

Yes, I agree. If there are no more fixes on master to release we can bump the major version and do a pre release.

@mrbean-bremen
Copy link
Member

@tebjan - the ongoing fixes on master are not related to .NET Core support, so I would suggest to make a pre-release for testing specifically .NET Core support. If new fixes accumulate meanwhile, you may make another pre-release later.

@tebjan
Copy link
Contributor

tebjan commented Jun 9, 2019

@mrbean-bremen sounds good! i'll do a local build and test it out.

@8m0
Copy link

8m0 commented Jul 8, 2019

Hi! Did you solve the problem The CreateDocument method can only be used to parse root <svg> elements. and Stack empty.. Also empty file after all?

@mrbean-bremen
Copy link
Member

I'm not aware of this problem. Can you file an issue describing the problem?

@8m0
Copy link

8m0 commented Jul 8, 2019

I am trying to convert SVG to PNG with this code:
`public IActionResult CodeplexToPng()
{

       var svgDocument = SvgDocument.Open("..\\qq\\lastCreated.svg");
        using (var smallBitmap = svgDocument.Draw())
        {
            var width = smallBitmap.Width;
            var height = smallBitmap.Height;
            if (width != 2000)// I resize my bitmap
            {
                width = 2000;
                height = 2000/smallBitmap.Width*height;
            }

            using (var bitmap = svgDocument.Draw(width, height))//I render again
            {
                bitmap.Save("..\\qq\\pngPath.png", ImageFormat.Png);
            }
        }

        return View();
   }`

When i start the method it shows:
Error: 0 : The CreateDocument method can only be used to parse root <svg> elements. Error: 0 : Stack empty..
After hundred or so this messages it creates empty black .png file.
empty file
errors

@mrbean-bremen
Copy link
Member

I understand you are using .NETCore?

@8m0
Copy link

8m0 commented Jul 8, 2019

I understand you are using .NETCore?

yes

@mrbean-bremen
Copy link
Member

Are you using master, or the nuget package? And which OS?

@8m0
Copy link

8m0 commented Jul 8, 2019

Are you using master, or the nuget package? And which OS?

nuget, windows 10

@mrbean-bremen
Copy link
Member

Hm, this exception happens if the root element is not an svg, actually this shall not be dependent on .NETCore. Can you show an example SVG that causes this issue?

@8m0
Copy link

8m0 commented Jul 8, 2019

lastCreated.zip

@mrbean-bremen
Copy link
Member

Ok, this looks fine at first glance. I may have another look later today.

@mrbean-bremen
Copy link
Member

Hm, I couldn't reproduce this. Also, I don't understand where this "Stack empty" message comes from - this is not logged.
Are you able to check this with master by building master yourself?

@gvheertum
Copy link
Member

@mrbean-bremen Did you also do a test what happens if you do a render within another render (like @8m0 did in his example), maybe the XML parser/reader somehow messes up if you try to render twice or try to render when there is another bitmap also in use (which might hint on issues with concurrency).

The Stack empty can be due to the type of exception used, we use InvalidOperationException, googling the exception and the stack message shows that apparently it's something related to this type of error. Maybe using (some of the) system exceptions is something to change (many guidelines and best-practice guides advice against using these).

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Aug 9, 2019

@gvheertum - I wrote a small test with the code given above and used it on the example file, though maybe I did something different. I will have a another go at this sometime later (though of course I'd be happy if someone else could tackle this ;)

@gvheertum
Copy link
Member

@gvheertum - I wrote a small test with the code given above and used it on the example file, though maybe I did something different. I will have a another go at this sometime later (though of course I'd be happy if someone else could tackle this ;)

I'm on it, I'll make a unittest to test this behavior and keep track of issues when rendering multiple times after each other.

By the way, what are your thoughts about the InvalidOperationException being thrown instead of a customized exception? I'm not even sure if the InvalidOperation is the correct type of exception, since it's more likely a parser or document error.

@gvheertum
Copy link
Member

gvheertum commented Aug 10, 2019

@mrbean-bremen I put it in a test-harness (see PR #549), I could not test it fully on Mac (somehow Mac goes crazy on fonts), but maybe you can give it a run on Windows.

Using a simple SVG without text showed no issues in the unittests when I did them, so if you also have the same result with the Windows run I think this issue can be closed.

Edit: after the font fix on Mac I was able to run with the file provided by @8m0 and no problems did occur.

@mrbean-bremen
Copy link
Member

Thanks for that! I did the test under Windows (with .NET Core) and it all passed. Though I shouldn't have bothered as the AppVeyor build already had passed :)

About the InvalidOperationException - I'm not sure. For me the usage looks right in this case, but generally I also prefer the usage of custom exceptions.

I would also tend to close this issue, as support for .NET Core is there, and all problems shall be handled in separate issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants