-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Closed
Copy link
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
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
$DataTable = [Data.DataTable]::new()
$null = $DataTable.Columns.Add('Date', [DateTime])
$Date = Get-Date
$Row = $DataTable.Rows.Add($Date)
$Row.Date = $Date # Error
$Row['Date'] = $Date # Error
$Row.Item('Date') = $Date # Works
$Row.Date = [DateTime]$Date # WorksLast working versions "PowerShell-7.2.0-preview.1" and "PowerShell-7.1.7".
First impacted version "PowerShell-7.2.0-preview.2".
Expected behavior
$Row.Date = $Date will put the DateTime object in the DateTime column.
Actual behavior
SetValueInvocationException: Exception setting "Date": "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <04/07/2022 19:42:04> in Date Column. Expected type is DateTime."
Error details
Exception :
Type : System.Management.Automation.SetValueInvocationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Exception setting "Date": "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <04/07/2022
19:58:39> in Date Column. Expected type is DateTime."
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : CatchFromBaseAdapterSetValue
InvocationInfo :
ScriptLineNumber : 5
OffsetInLine : 1
HistoryId : -1
ScriptName : C:\Users\illym\Desktop\Temp\PBug.ps1
Line : $Row.Date = $Date
PositionMessage : At C:\Users\illym\Desktop\Temp\PBug.ps1:5 char:1
+ $Row.Date = $Date
+ ~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\illym\Desktop\Temp
PSCommandPath : C:\Users\illym\Desktop\Temp\PBug.ps1
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\Users\illym\Desktop\Temp\PBug.ps1: line 5
at <ScriptBlock>, <No file>: line 1
TargetSite :
Name : BasePropertySet
DeclaringType : System.Management.Automation.Adapter, System.Management.Automation, Version=7.3.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : Exception setting "Date": "Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <04/07/2022
19:58:39> in Date Column. Expected type is DateTime."
Data : System.Collections.ListDictionaryInternal
InnerException :
Type : System.ArgumentException
Message : Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.Couldn't store <04/07/2022 19:58:39> in Date Column.
Expected type is DateTime.
TargetSite :
Name : set_Item
DeclaringType : System.Data.DataColumn
MemberType : Method
Module : System.Data.Common.dll
InnerException :
Type : System.InvalidCastException
TargetSite :
Name : ChkCast_Helper
DeclaringType : System.Runtime.CompilerServices.CastHelpers, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
MemberType : Method
Module : System.Private.CoreLib.dll
Message : Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.IConvertible'.
Source : System.Private.CoreLib
HResult : -2147467262
StackTrace :
at System.Data.Common.DateTimeStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)
Source : System.Data.Common
HResult : -2147024809
StackTrace :
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Management.Automation.DataRowAdapter.PropertySet(PSProperty property, Object setValue, Boolean convertIfPossible)
at System.Management.Automation.Adapter.BasePropertySet(PSProperty property, Object setValue, Boolean convert)
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.Adapter.BasePropertySet(PSProperty property, Object setValue, Boolean convert)
at System.Management.Automation.PSProperty.SetAdaptedValue(Object setValue, Boolean shouldConvert)
at System.Management.Automation.PSProperty.set_Value(Object value)
at System.Management.Automation.Language.PSSetMemberBinder.SetAdaptedValue(Object obj, String member, Object value)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
FullyQualifiedErrorId : CatchFromBaseAdapterSetValue
InvocationInfo :
ScriptLineNumber : 5
OffsetInLine : 1
HistoryId : -1
ScriptName : C:\Users\illym\Desktop\Temp\PBug.ps1
Line : $Row.Date = $Date
PositionMessage : At C:\Users\illym\Desktop\Temp\PBug.ps1:5 char:1
+ $Row.Date = $Date
+ ~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\illym\Desktop\Temp
PSCommandPath : C:\Users\illym\Desktop\Temp\PBug.ps1
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\Users\illym\Desktop\Temp\PBug.ps1: line 5
at <ScriptBlock>, <No file>: line 1Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime