Page 1 of 1

Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 9:22 am
by dakotazinn
To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.164
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0

*** Please add details and screenshots as needed below. ***

When making a restmethod request using the 'Run' button, I get the following error:

Cannot access a disposed object.
Object name: 'ProgressBar'.


On startup, I have a request that gets data from Google Sheets, and it runs relatively quickly.
However, I've been running into this error during the request and it causes an issue with the -outfile parameter. (it writes a blank/empty file content)

When I run the same code in ISE and in powershell CLI, I do not see this issue, it is also not seen when the application is built and run. This only occurs when the progress bar window from PowerShell Studio pops up and closes too quickly.



DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Re: Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 9:58 am
by davidc
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]

Re: Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 10:23 am
by jvierra
What "ProgressBar" window are you referring to? Have you created a custom form with a ProgressBar?

If this is the automatic progress indicator then this is caused by PowerShell and automatically shows as a GUI in ISE and in PSS and as a text progress indicator in PS CLI.

Have you checked the "threading" setting? Also be sure you are running the correct version of PowerShell (Platform setting).

Re: Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 12:08 pm
by dakotazinn
It is the automatic progress indicator.
My threading setting is set to STA, since I am running forms.
and I made sure the version is correct.

And Yes, the progress indicator automatically shows, but when you use the 'Run' command in PS Studio and running Forms scripts, it shows up as an external progress window, and that's when i run into the error.

My forms have no progress bars, so it couldn't be caused by my application. and since this doesn't show an error when the application is built/packaged, it leads me to believe that it has something to do with the way that PowerShell Studio creates and disposes of the progress bar, since the progress bar can't show up in a console as a form script.

Re: Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 12:21 pm
by jvierra
THe progress bar is not don by PSS. It is how PS displays it when PS code is run in a GUI. THe same will happen in the ISE.

TO disable this just add the following to the code:

$ProgressPreference = 0[/b}

Also check your threading and the platform setting you are using.

Re: Invoke-RestMethod disposal error

Posted: Thu Jun 13, 2019 1:51 pm
by jvierra
You also fail to say which platform you are running this on - under platform settings. It shows you which version of PowerShell is being used by PSS when "Run" is clicked.