32 or 64 bit version of product: 64
Operating system: Microsoft Windows [Version 10.0.14393]
32 or 64 bit OS: 64
The following example code works when run in powershell ise, or when clicking the run button, but not when compiled with PowerShell Studio:
- #$SpeechSynth.GetInstalledVoices().VoiceInfo
- Add-Type -AssemblyName System.Speech
- $SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
- $SpeechSynth.SelectVoice("Microsoft Zira Desktop")
- $Browser = New-Object System.Net.WebClient
- $Browser.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- $CatFact = (ConvertFrom-Json (Invoke-WebRequest -Verbose -Uri https://catfact.ninja/fact -UseBasicParsing))
- $CatFact.fact
- $SpeechSynth.Speak("Did you know ?")
- $SpeechSynth.Speak($CatFact.fact)
These are the error messages generated by the code when compiled (you could ignore the last one):
The property 'Credentials' cannot be found on this object. Verify that the property exists and can be set.
At line:6 char:1
+ $Browser.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNet ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Invoke-WebRequest : Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section.
At line:8 char:31
+ ... tFrom-Json (Invoke-WebRequest -Verbose -Uri https://catfact.ninja/fac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], ConfigurationErrorsException
+ FullyQualifiedErrorId : System.Configuration.ConfigurationErrorsException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Exception calling "Speak" with "1" argument(s): "Value cannot be null.
Parameter name: prompt"
At line:11 char:1
+ $SpeechSynth.Speak($CatFact.fact)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
What is it about compiling the code that breaks this functionality? Is this a known issue? Is there a setting that I have incorrect?