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

Getting NullReferenceException in ToCss() #134

Closed
ac-lap opened this issue Jan 19, 2022 · 6 comments
Closed

Getting NullReferenceException in ToCss() #134

ac-lap opened this issue Jan 19, 2022 · 6 comments

Comments

@ac-lap
Copy link

ac-lap commented Jan 19, 2022

I use ExCSS library to parse the CSS file content, edit some of the properties and then generate the updated CSS string. The code is something like this -

var parser = new StylesheetParser();
var stylesheet = parser.Parse(cssInput);
// edit rules here
processedCss = stylesheet.ToCss();

But for lot of css strings, the parser works fine, but the .ToCSS() method throws null ref exception.
The simplest one being this -

@page {
    margin-bottom: 5pt;
    margin-top: 5pt
    }

I have attached other problematic css files.
Prob-CSS-2.txt
Prob-CSS-1.txt

@majora2007
Copy link

Just came to give the same report. I didn't get this exception in the previous version.

@majora2007
Copy link

@TylerBrinks any ideas on this regression?

@TylerBrinks
Copy link
Owner

TylerBrinks commented Jul 6, 2022

The code shouldn't have change substantially - I'm investigating. I have a guess that it's an issue with parsing children of the @page directive.

@majora2007
Copy link

That's also what I'm thinking. I saw another issue that seems to have traced it down to that. I noticed @page as well in the css I was processing.

I had assumed anything that couldn't be processed would be dropped, but it could be some complex logic. Thanks for taking a look into this. My epub reader relies on this library for rendering.

@TylerBrinks
Copy link
Owner

Version 4.1.4 is available on NuGet.org

@majora2007
Copy link

majora2007 commented May 25, 2023

Sorry to reopen, but this issue isn't fixed on v4.2.0 still. I have:

@page {
    margin-bottom: 5pt;
    margin-top: 5pt
    }

which still throws:

System.NullReferenceException: Object reference not set to an instance of an object.
   at ExCSS.PageRule.get_SelectorText()
   at ExCSS.PageRule.ToCss(TextWriter writer, IStyleFormatter formatter)
   at ExCSS.CompressedStyleFormatter.WriteJoined(StringBuilder sb, IEnumerable`1 elements, String separator, Boolean first)
   at ExCSS.CompressedStyleFormatter.ExCSS.IStyleFormatter.Sheet(IEnumerable`1 rules)
   at ExCSS.Stylesheet.ToCss(TextWriter writer, IStyleFormatter formatter)
   at ExCSS.FormatExtensions.ToCss(IStyleFormattable style, IStyleFormatter formatter)
   at ExCSS.FormatExtensions.ToCss(IStyleFormattable style)

when doing .ToCSS()

I can validate that a PageRule is created, but there are no margins.

image

Edit: This happens not only from css with Page, but you can see here a CSS which is throwing. This has made it so I can't upgrade from v4.1.0. But with the new contributors, I would really like to update to get the newest support.

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

No branches or pull requests

3 participants