【问题标题】:How to use the HTML Tidy .NET DLL wrapper in PowerShell?如何在 PowerShell 中使用 HTML Tidy .NET DLL 包装器?
【发布时间】:2009-09-28 13:52:38
【问题描述】:

我正在尝试在 PowerShell 2.0 中使用 HTML Tidy .NET wrapper

这是一个使用 C# 的工作示例(包装分发中包含的 TestIt.cs):

using Tidy;
Document tdoc = new Document();

我在 PowerShell 中执行此操作:

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

我收到以下错误:

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

附加信息:

> [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

发生了什么事?

【问题讨论】:

    标签: .net windows powershell htmltidy


    【解决方案1】:

    尝试使用 DocumentClass 类型创建文档,例如:

    $doc = new-object tidy.documentclass
    

    C# 在使用互操作程序集和 IIRC 时会发挥一些作用,其中之一是采用“Foo”的类规范,然后创建“FooClass”的实例。

    【讨论】:

    • 起初我认为这不起作用...然后我意识到我正在尝试将 32 位 DLL 加载到 64 位 Powershell 会话中...我切换到 32 位PowerShell 会话,它的工作原理!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 2014-07-09
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2022-11-02
    相关资源
    最近更新 更多