簡體   English   中英

Function 從 Powershell 5 移植到 Powershell 7 失敗,並顯示“對象引用未設置為對象的實例”

[英]Function ported from Powershell 5 to Powershell 7 fails with “object reference not set to an instance of an object”

以下代碼在 powershell 5.1 中按預期工作:

function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") {
    Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.SelectVoice($Voice)
    $speak.Speak($Message)
}

然而,在 powershell 7.1.0(預覽版 5)中,執行失敗,“對象引用未設置為對象的實例”,我實際上迷路了。 谷歌搜索沒有多大幫助,因為看起來這個錯誤可能會在非常不同的上下文中遇到。 所以,PowerShell 專家,問你一個問題,我該如何解決這個問題。

在此處輸入圖像描述

我試圖在正文中聲明參數( object reference not set to an instance of an object ),希望可能存在一些語義差異,但這沒有幫助。

這是一個已知問題,因為在構建 PS v7 的 .NET Core 中不存在一些所需的功能。 看起來像提出了一個錯誤,但它在沒有修復的情況下被關閉:

System.Speech.Synthesis.SpeechSynthesizer Speak 方法拋出 Object 引用未設置為 PowerShell.6 中的 object 的實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM