這可能是一個非常簡單的問題,但我完全失去了,尋找答案沒有幫助。Powershell無法找到類型[System.Windows.Forms.KeyEventHandler]
我有一些PowerShell代碼來顯示一個簡單的圖形用戶界面與文本框。一些文本框允許用戶按Enter鍵來運行Button_Click代碼。當我嘗試運行PS1劇本,我得說了以下錯誤:
Unable to find type [System.Windows.Forms.KeyEventHandler].
Make sure that the assembly that contains this type is loaded.At C:\Scripts\GUI-Testing.ps1:161 char:1
$TestVar=[System.Windows.Forms.KeyEventHandler]
CategoryInfo : InvalidOperation: (System.Windows.Forms.KeyEventHandler:TypeName)
FullyQualifiedErrorId : TypeNotFound
奇怪的一部分,如果我關閉GUI然後重新運行該腳本,我沒有得到Unable to find type
錯誤並按下Enter作品如預期的。
思考我有一個答案,我嘗試使用[void][reflection.assembly]::Load('System.Windows.Forms.KeyEventHandler')
這給這個錯誤Exception calling "Load" with "1" argument(s): "Could not load file or assembly 'System.Windows.Forms.KeyEventHandler' or one of its dependencies. [FileNotFoundException]
我應該用'[void] [reflection.assembly] :: Load('System.Windows.Forms,Version = 2.0.0.0,文化=中立')' – user4317867