Skip to content

NullReferenceException when computing style #159

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

Closed
5 tasks done
meziantou opened this issue Feb 26, 2024 · 0 comments · Fixed by #160
Closed
5 tasks done

NullReferenceException when computing style #159

meziantou opened this issue Feb 26, 2024 · 0 comments · Fixed by #160
Labels
Milestone

Comments

@meziantou
Copy link
Contributor

meziantou commented Feb 26, 2024

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp.Css?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Xml for Xml support)
  • Did you perform a search in the issues?

Description

AngleSharp fails to compute style for <div style=""></div> with the latest preview 1.0.0-beta.122

System.NullReferenceException: Object reference not set to an instance of an object.
   at AngleSharp.Css.Dom.CssStyleDeclaration.ChangeDeclarations(IEnumerable`1 decls, Predicate`1 defaultSkip, Func`3 removeExisting)
   at AngleSharp.Css.Dom.CssStyleDeclaration.SetDeclarations(IEnumerable`1 decls)
   at AngleSharp.Css.StyleCollectionExtensions.ComputeCascadedStyle(IStyleCollection styles, IElement element, ICssStyleDeclaration parent)
   at AngleSharp.Css.StyleCollectionExtensions.ComputeDeclarations(IStyleCollection styles, IElement element, String pseudoSelector)
   at AngleSharp.Dom.WindowExtensions.GetComputedStyle(IWindow window, IElement element, String pseudo)
   at Program.<Main>$(String[] args) in D:\source\ConsoleApp4\ConsoleApp4\Program.cs:line 16
   at Program.<Main>(String[] args)

Steps to Reproduce

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AngleSharp" Version="1.1.1-beta.386" />
    <PackageReference Include="AngleSharp.Css" Version="1.0.0-beta.122" />
  </ItemGroup>

</Project>
using AngleSharp.Css;
using AngleSharp;
using AngleSharp.Io;
using AngleSharp.Dom;

var configuration = new AngleSharp.Configuration()
            .WithDefaultLoader()
            .WithRenderDevice(new DefaultRenderDevice() { ViewPortHeight = 100, ViewPortWidth = 100 });

var context = BrowsingContext.New(configuration);
using var response = VirtualResponse.Create(request => request.Content("""
    <div style="transform-origin: bottom"></div>
    """));
var document = await context.OpenAsync(response, CancellationToken.None);
var element = document.QuerySelector("div");
var style = document.DefaultView.GetComputedStyle(element); // throw NRE

Expected Behavior

No exception

Actual Behavior

It throws a NullReferenceException

Possible Solution / Known Workarounds

No response

@meziantou meziantou added the bug label Feb 26, 2024
@meziantou meziantou changed the title NullReferenceException when computing style for transform-origin: bottom NullReferenceException when computing style Feb 26, 2024
@FlorianRappl FlorianRappl added this to the v1.0 milestone Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants