diff --git a/src/Microsoft.PowerShell.Workflow.ServiceCore/ServiceCore/WorkflowCore/PSActivityBase.cs b/src/Microsoft.PowerShell.Workflow.ServiceCore/ServiceCore/WorkflowCore/PSActivityBase.cs index 92c0703529..08488f2637 100644 --- a/src/Microsoft.PowerShell.Workflow.ServiceCore/ServiceCore/WorkflowCore/PSActivityBase.cs +++ b/src/Microsoft.PowerShell.Workflow.ServiceCore/ServiceCore/WorkflowCore/PSActivityBase.cs @@ -3956,7 +3956,12 @@ namespace Microsoft.PowerShell.Activities { try { - runspace.SessionStateProxy.PSVariable.Set(name, value); + var psvar = runspace.SessionStateProxy.PSVariable.Get(name); + if (psvar == null || (psvar.Options & ScopedItemOptions.ReadOnly) == 0) + { + // don't try to overwrite read-only variables values + runspace.SessionStateProxy.PSVariable.Set(name, value); + } } catch (PSNotSupportedException) { diff --git a/test/fullclr/PowerShellGithubDev.Tests.ps1 b/test/fullclr/PowerShellGithubDev.Tests.ps1 index 628f9f1e2c..c82a89a1db 100644 --- a/test/fullclr/PowerShellGithubDev.Tests.ps1 +++ b/test/fullclr/PowerShellGithubDev.Tests.ps1 @@ -30,7 +30,8 @@ Describe 'build.psm1 and powershell.exe' { } It 'loads Microsoft.PowerShell.Workflow.ServiceCore.dll' { - workflow wfTest {}; wfTest ## Trigger the loading of ServiceCore.dll + workflow wfTest { Split-Path $pwd } + wfTest | Should Not Be $null ## Also trigger the loading of ServiceCore.dll [Microsoft.PowerShell.Workflow.PSWorkflowJob].Assembly.Location | Should Be ( Join-Path $env:DEVPATH Microsoft.PowerShell.Workflow.ServiceCore.dll) }