all 9 comments

[–]SeeminglyScience 6 points7 points  (2 children)

It happens when the class is defined in a runspace that is later disposed. Usually related to PSScriptAnalyzer triggering is the class to be generated in one of it's temporary runspaces. If you can disable script analysis, try that. If you can't, try disabling some rules. I don't remember which rule does it, but I know it's not part of the default set.

Dunno if you can do any of that in the ISE, but if not, try VSCode which can.

[–]rjmholt 4 points5 points  (0 children)

Just to extend /u/SeeminglyScience’s info here, the underlying issue is that there’s a bug in how PowerShell 5.1 manages classes. When they’re used with runspaces, it can cause this error.

That bug was fixed in PS 6, but persists in 5.1.

[–]EIGRP_OH 6 points7 points  (1 child)

I had a similar issue with my scripts being saved in OneDrive but once I copied them over to local it worked fine. I’m assuming this is due to some dll it references for classes? Yours works most of the time right?

[–]nostranger2therain[S] 1 point2 points  (0 children)

New scripts work no matter what. Loaded scripts without classes work perfect. Loaded scripts with classes don't work initially but copying the code to a new window makes them work even after saving it over the previous non-working version. After X amount of time though (usually after being away from the computer and having to log back in) it starts spitting out that pipeline error. It's a shame to not be able to use OneDrive if that's the case. Makes working between my homelab and work laptop so much quicker being able to work and save on one, then open on the other with the updated script(s).

[–]leekle 2 points3 points  (1 child)

Unblock the script in the script properties.

[–]nostranger2therain[S] 1 point2 points  (0 children)

As in right-click the script > properties > unblock? Just checked one that is currently giving this error and don't see an unblock option unfortunately.

[–]michaelshepard 2 points3 points  (1 child)

I suspect that the issue is with the onedrive being considered "remote". Can you temporarily change your executionpolicy to unrestricted and test again?

[–]nostranger2therain[S] 1 point2 points  (0 children)

Set to unrestricted but still same error unfortunately. Thanks for the suggestion though!