Invoke-RestMethod disposal error

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
dakotazinn
Posts: 7
Joined: Thu Apr 13, 2017 8:00 am

Invoke-RestMethod disposal error

Post by dakotazinn » Thu Jun 13, 2019 9:22 am

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

User avatar
davidc
Posts: 5878
Joined: Thu Aug 18, 2011 4:56 am

Re: Invoke-RestMethod disposal error

Post by davidc » Thu Jun 13, 2019 9:58 am

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Invoke-RestMethod disposal error

Post by jvierra » Thu Jun 13, 2019 10:23 am

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).

User avatar
dakotazinn
Posts: 7
Joined: Thu Apr 13, 2017 8:00 am

Re: Invoke-RestMethod disposal error

Post by dakotazinn » Thu Jun 13, 2019 12:08 pm

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.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Invoke-RestMethod disposal error

Post by jvierra » Thu Jun 13, 2019 12:21 pm

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.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Invoke-RestMethod disposal error

Post by jvierra » Thu Jun 13, 2019 1:51 pm

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.

Post Reply