How to use the HTML Tidy .NET DLL wrapper in PowerShell?

删除回忆录丶 提交于 2019-12-08 03:30:28

问题


I'm trying to use the HTML Tidy .NET wrapper in PowerShell 2.0.

Here is a working example using C# (TestIt.cs included in the wrapper distribution):

using Tidy;
Document tdoc = new Document();

I'm doing this in PowerShell:

[Reflection.Assembly]::LoadFile("C:\Users\e-t172\Desktop\Tidy.NET\Tidy.dll")
New-Object Tidy.Document

I get the following error:

New-Object : Constructor not found. Cannot find an appropriate constructor for type Tidy.Document.
At line:1 char:11
+ New-Object <<<<  Tidy.Document
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

Additional info:

> [Reflection.Assembly]::LoadFile("C:\Users\e-t172\Desktop\Tidy.NET\Tidy.dll").getTypes()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    ITidyDocumentEvents
True     True     TidyReportLevel                          System.Enum
True     True     __MIDL_ITidyDocument_0008                System.Enum
True     False    DocumentClass                            System.__ComObject
True     False    ITidyDocumentEvents_Event
True     True     ITidyDocumentEvents_OnMessageEventHan... System.MulticastDelegate
True     False    Document
True     False    ITidyDocument
True     True     TidyOptionId                             System.Enum
True     True     __MIDL_ITidyDocument_0002                System.Enum
False    False    ITidyDocumentEvents_SinkHelper           System.Object
False    False    ITidyDocumentEvents_EventProvider        System.Object

What's going on?


回答1:


Try creating the document using the DocumentClass type e.g.:

$doc = new-object tidy.documentclass

C# does some magic when using interop assemblies and IIRC one of those is to take a class spec of "Foo" and in turn create an instance of "FooClass".



来源:https://stackoverflow.com/questions/1487166/how-to-use-the-html-tidy-net-dll-wrapper-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!