Class 使用PowerShell访问DLL类

Class 使用PowerShell访问DLL类,class,powershell,dll,constructor,Class,Powershell,Dll,Constructor,我正在尝试使用PowerShell控制Bluethooth加密狗,该加密狗发布了API文档和dll 名称空间“Nordicsemi”下有一个MasterEmulator类可用,我用C#测试了它,我可以用MasterEmulator构造函数创建一个新实例,如下所示,所有其他函数也可以正常工作 MasterEmulator masterEmulator = new MasterEmulator(); 不过,我尝试使用下面的脚本对PowerShell执行相同的操作 [System.Reflectio

我正在尝试使用PowerShell控制Bluethooth加密狗,该加密狗发布了API文档和dll

名称空间“Nordicsemi”下有一个MasterEmulator类可用,我用C#测试了它,我可以用MasterEmulator构造函数创建一个新实例,如下所示,所有其他函数也可以正常工作

MasterEmulator masterEmulator = new MasterEmulator();
不过,我尝试使用下面的脚本对PowerShell执行相同的操作

[System.Reflection.Assembly]::LoadFile($fullpath)
$MasterEmulatorInstance = New-Object Nordicsemi.MasterEmulator
我得到以下错误:

+ $MasterEmulatorInstance = New-Object Nordicsemi.MasterEmulator
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [New-Object],MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
dll似乎加载正确,我只是无法让构造函数工作,我检查了其他相关帖子,但新对象似乎是从.Net dll访问类的唯一方法。我不知道我做错了什么,任何提示都将不胜感激,谢谢

更新: 感谢您的回复,我尝试了更多加载程序集的方法,如下所示

[System.Reflection.Assembly]::LoadFrom($fullpath) | Out-Null
而且也没有Out-Null cmdlet

[System.Reflection.Assembly]::LoadFrom($fullpath)
输出显示

GAC    Version        Location                                                                                                                                                       
---    -------        --------                                                                                                                                                       
False  v4.0.30319     D:\Test\MasterEmulator.dll 
而且还是给我同样的错误,我也试过下面的方法

[reflection.assembly]::loadwithpartialname("MasterEmulator.dll") | Out-Null
Add-Type -Path $fullpath
但仍然不走运,当我调用构造函数时,所有这些方法都会给出完全相同的错误

New-Object : 以 "0" 引數呼叫 ".ctor" 時發生例外狀況: "無法載入檔案或組件     'IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1' 或其相依性的其中之一。 系統找不到指定的檔案。"
位於 D:\Test\test.ps1:3 字元:27
+ $MasterEmulatorInstance = New-Object Nordicsemi.MasterEmulator
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [New-Object],MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

很抱歉错误消息中的中文,因为我正在运行的系统是中文的,还有其他想法吗?

尝试使用
LoadFrom
。下面是如何加载
MSTranslitTools.DLL
,它会加载


了解差异。另请参见SO问题。

注意,您可以使用
添加类型-Path$dll
加载程序集。
function load_transliterate(){
    $dll = Resolve-Path ".\tools\transliterate\MSTranslitTools.DLL"
    [System.Reflection.Assembly]::LoadFrom($dll) | out-null

    $specfile = Resolve-Path "Serbian Cyrillic to Latin.tms"      
    $tspec = [System.NaturalLanguage.Tools.TransliteratorSpecification]::FromSpecificationFile($specfile)

    $script:trans = [System.NaturalLanguage.Tools.Transliterator]::FromSpecification($tspec)

    Write-Verbose "Transliteration: $($trans.Input) -> $($trans.Output)"
}