Repository navigation
Open
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
In C#, it is possible for a property to override only the set for a property that has both a get and a set. However, PowerShell will believe that the property only has a set.
Simple steps to reproduce:
$Source = @"
public class MyBase
{
protected int _foo;
public virtual int Foo {
get => _foo;
set => _foo = value;
}
}
public class BlahBlah : MyBase {
public override int Foo {
set => _foo = value + 1;
}
}
"@
Add-Type -TypeDefinition $Source
$b = New-Object -TypeName BlahBlah
$f = $b.FooExpected behavior
I would expect the above snippet to assign the value of `0` to `$f`Actual behavior
Raises the error
> Cannot get property value because "Foo" is a write-only property.Error details
Exception :
Type : System.Management.Automation.RuntimeException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Cannot get property value because "Foo" is a write-only property.
HResult : -2146233087
CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : WriteOnlyProperty
InvocationInfo :
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 6
Line : $f = $b.Foo
Statement : $f = $b.Foo
PositionMessage : At line:1 char:1
+ $f = $b.Foo
+ ~~~~~~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
TargetSite : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure,
System.Runtime.CompilerServices.CallSite, System.Object)
Message : Cannot get property value because "Foo" is a write-only property.
Data : System.Collections.ListDictionaryInternal
Source : Anonymously Hosted DynamicMethods Assembly
HResult : -2146233087
StackTrace :
at CallSite.Target(Closure, CallSite, Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interpret
edFrame frame)
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : WriteOnlyProperty
InvocationInfo :
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 6
Line : $f = $b.Foo
Statement : $f = $b.Foo
PositionMessage : At line:1 char:1
+ $f = $b.Foo
+ ~~~~~~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1Environment data
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24…
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
No response
Reacted by Michael Klement
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Activity
vcsjones commentedon Feb 17, 2025
To add, this was originally reported to .NET because there are some classes that have this shape. Some classes only override the
setof a property (to have additional validation, for example)vcsjones commentedon Feb 18, 2025
Further adding - this can be reproduced on PowerShell 7.5 using the following APIs built-in to .NET:
(Note this particular example is Linux only)
SeeminglyScience commentedon Feb 25, 2025
The Engine WG discussed this and agree it's a bug. Not marking as up for grabs only because this would be a particularly challenging issue to take on if you are not already familiar with the systems involved. Those who are sufficiently familiar are welcome to open a PR
microsoft-github-policy-service commentedon Aug 24, 2025
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.