Why isn’t PowerShell suggesting methods for ‘[HtmlAgilityPack.HtmlDocument]’ like it does with ‘New-Object’?

0
1
Asked By CuriousCoder123 On

I'm working with the HtmlAgilityPack library and trying to understand how to load it in PowerShell. I typically load it using `Add-Type -path ".HtmlAgilityPack.dll"` and I expect to see method suggestions when I type `[HtmlAgilityPack.HtmlDocument]::loadHt...`. However, I'm not seeing any suggestions for methods. On the other hand, when I create an object with `New-Object HtmlAgilityPack.HtmlDocument`, I do get method suggestions. Can anyone explain why `[HtmlAgilityPack.HtmlDocument]` isn't showing the methods like `new-object` does? I'm currently using PowerShell version 7.4.

1 Answer

Answered By PowerShellGuru42 On

It looks like you're trying to use the static method syntax, but methods like `LoadHtml` aren't static. That's why you don't get suggestions when using `[HtmlAgilityPack.HtmlDocument]::loadHt...`. You can check the static members by using `[HtmlAgilityPack.HtmlDocument] | Get-Member -static` to see what's available directly. Unfortunately, there isn’t a comprehensive documentation for the classes, but examples can be helpful. Just remember that you need to actually create an instance to access instance methods.

CuriousCoder123 -

Aah, that is what it was.. I've been away, completely forgot about that, thank!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.