5.1 Env. Scripts not executing after Upgrade to 5.0

Product: PowerShell Universal
Version: 5.0

since upgrading to 5.0 all scripts executed within the 5.1 environment fail with following error:

Import-Module : Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, 
PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
At C:\Program Files (x86)\Universal\UniversalHost.psm1:9 char:5
+     Import-Module $LocalHost
+     ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
 
Exception calling "StartJob" with "3" argument(s): "Could not load file or assembly 
'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its 
dependencies. The system cannot find the file specified."
At C:\Program Files (x86)\Universal\UniversalHost.psm1:28 char:13
+             [UniversalHost.AgentService]::StartJob($Port, $ParentProc ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

Do you maybe have multiple version of the Universal module installed, maybe causing a conflict?

You can run Get-Module Universal* -List and share the output.

This is likely because PSU is calling powershell.exe directly. We need to make this more adaptable and will be fixed in 5.0.2. In the meantime, I would check to see if you have a Windows PowerShell environment with the path to powershell.exe. Try changing the path to “Windows PowerShell 5.1” and it will use the new hosting executable rather than powershell.exe and will load assemblies properly.

3 Likes

This caught me a bit off guard as well, it appears that Universal can’t (or won’t?) change existing environments to use the new hosting executable, I ended up deleting all the old environments to generate the right ones.

We can make PSU change the behavior for this. Miss on our part.

2 Likes

I upgraded from v4 to v5.0.8 and I am seeing this issue with with PowerShell 5.1.

All of my script now thorw out the same error Could not load file or assembly. It also throws out errors that the module aren’t loaded, no matter if I set the environment to load all modules or import-module, The specified module 'Microsoft.Graph' was not loaded because no valid module file was found in any module directory

Initially after the uprage I had some old PowerShell Environment. I deleted all of these and did the auto detect, so now I have a PowerSheel 5 with the path of “Windows PowerShell 5.1” and it is stil lthrowing the same error.

Is there anything else I can do to get these scripts working again?