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.
This topic is 4 years and 9 months 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.
Locked
User avatar
dakotazinn
Posts: 20
Last visit: Wed Mar 31, 2021 7:12 am

Invoke-RestMethod disposal error

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

Re: Invoke-RestMethod disposal error

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Invoke-RestMethod disposal error

Post 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).
User avatar
dakotazinn
Posts: 20
Last visit: Wed Mar 31, 2021 7:12 am

Re: Invoke-RestMethod disposal error

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Invoke-RestMethod disposal error

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Invoke-RestMethod disposal error

Post 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.
This topic is 4 years and 9 months 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.
Locked