"Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section." only when compiled

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
ChrisFrench
Posts: 2
Last visit: Fri Jun 02, 2023 6:59 am

"Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section." only when compiled

Post by ChrisFrench »

Product, version and build: Powershell Studio 5.6.160
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:
  1. #$SpeechSynth.GetInstalledVoices().VoiceInfo
  2. Add-Type -AssemblyName System.Speech
  3. $SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
  4. $SpeechSynth.SelectVoice("Microsoft Zira Desktop")
  5. $Browser = New-Object System.Net.WebClient
  6. $Browser.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
  7. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  8. $CatFact = (ConvertFrom-Json (Invoke-WebRequest -Verbose -Uri https://catfact.ninja/fact -UseBasicParsing))
  9. $CatFact.fact
  10. $SpeechSynth.Speak("Did you know ?")
  11. $SpeechSynth.Speak($CatFact.fact)
it looks like there is something preventing the use or access of credentials of System.Net.WebClient objects and preventing the creation of web proxies. I'm assuming the two are related and that they both are rooted in a failure of credentials to pass properly into a compiled script. I would like to be able to compile scripts that parse webpages.

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?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section." only when compiled

Post by davidc »

What packager settings are you using?
Make sure the packager is using the same settings as PowerShell Studio. For example, the PowerShell version and platform setting (x86 vs x64).
David
SAPIEN Technologies, Inc.
User avatar
ChrisFrench
Posts: 2
Last visit: Fri Jun 02, 2023 6:59 am

Re: "Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section." only when compiled

Post by ChrisFrench »

it fails in 32 bit and 64 bit modes, fails elevated and as mortal user, fails as command line, silent, and windows application. It also fails in the same way when compiled by powerGUI, so i'm thinking that it must be a low level failure.

Also, as a side note, my main goal is to get another internal application to work, not just "cat facts", this is just an excellent example script.

I'm trying to compile a script that uses this same method and fails the same way.

Thanks for the fast reply!
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section." only when compiled

Post by davidc »

Start off with simple test script:

Code: Select all

$Browser = New-Object System.Net.WebClient
if($null -eq $Browser)
{
	Write-Host "Null Browser"
}
elseif($null -eq $Browser.Proxy)
{
	Write-Host "Null Proxy"
}
Your script is assuming Proxy is not null, which might not be the case. You could try using:

Code: Select all

[System.Net.WebRequest]::GetSystemWebProxy()
It is also possible there is firewall issue at play here.
David
SAPIEN Technologies, Inc.
This topic is 5 years old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.