-
-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
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.Xmlfor 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 NREExpected Behavior
No exception
Actual Behavior
It throws a NullReferenceException
Possible Solution / Known Workarounds
No response