-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Reactions are currently unavailable
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