2009-09-28 88 views
2

我試圖在PowerShell 2.0中使用HTML Tidy .NET wrapper如何在PowerShell中使用HTML Tidy .NET DLL封裝器?

下面是一個使用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 

發生了什麼事?

回答

5

嘗試建立使用中的DocumentClass類型如文件:使用互操作程序和IIRC其中之一是採取「富」的一類規範,進而創建一個實例時

$doc = new-object tidy.documentclass 

C#做一些魔術「FooClass」。

+0

起初我以爲這不起作用......然後我意識到我試圖將32位DLL加載到64位Powershell會話中......我切換到32位PowerShell會話,它工作正常! – 2009-09-28 17:09:32

相關問題