You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateTimeOffset should be treated as a primitive for serialization #3172
Among the many new types in .NET added to work around problems in the legacy types there is a new System.DateTimeOffset, which is just a System.DateTime plus an Offset (i.e. the original timezone) -- I won't explain why this is useful, but MSDN does.
This class should just work in PowerShell, just like the original DateTime.
Currently it doesn't, because when you pass it over a remote connection it comes out as Deserialized.DateTimeOffset and the scripter is forced to manually re-create a DateTimeOffset object.
Joel Bennett (@Jaykul) Good catch! Thanks!
(I figured that we use an older version. Strange that I couldn't make the fix in code. Most likely I should did dotnet restore)
PowerShell remoting uses it's own serialization mechanism as described in protocol specification MS-PSRP, section 2.2.5. By design, a limited, fixed set of types deserialize with fidelity. This list is available in MS-PSRP section 2.2.5.1 (see https://msdn.microsoft.com/en-us/library/dd305931.aspx )
Adding support for new primitive types requires changes to both the code/protocol and protocol specifications. The serialization code is in
src\System.Management.Automation\engine\Serialization.cs
src\System.Management.Automation\engine\SerializationStrings.cs
(Note: you can use the types files and Update-TypeData to specify custom deserializations in the local runspace but these need to be set up in each session.)
For PowerShell 6.0, it seems reasonable that we expand the set of types we serialize with fidelity but we should do this deliberately. I suggest opening an RFC for this so we can get a canonical list of the new types we want to handle.
@WG-Remoting
Remoting working group: Adding new remoting types requires updating the remoting protocol version and associated documents, which is a very large work item. It is unlikely that we would do this just for a single new type, but this could be part of a planned protocol upgrade that encompasses many enhancements. There is currently no plan to do this, but in the meantime, types can be deserialized into concrete types using PowerShell's extended type system over remoting.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 23, 2023
How can I work around this issue? When call a powershell script via a C# application I'm getting an exception regarding mismatched types: System.DateTimeOffset vs Deserialized.DateTimeOffset.
Activity
iSazonov commentedon Feb 22, 2017
Serialization of primitive types is based on XmlConvert class but CoreCLR is still not support ToDateTimeOffset
If the Issue will be approved, then we should come back to it after we move on .Net Standart 2.0.
Jaykul commentedon Feb 27, 2017
What do you mean Ilya (@iSazonov), it looks like it's already there, even in the version you shipped in 6.0.0.10?
https://github.com/dotnet/corefx/blob/f0ccd9742065ee2aa296448fe3dd38ef6ff77af9/src/System.Private.Xml/src/System/Xml/XmlConvert.cs#L863
iSazonov commentedon Feb 27, 2017
Joel Bennett (@Jaykul) Good catch! Thanks!
(I figured that we use an older version. Strange that I couldn't make the fix in code. Most likely I should did
dotnet restore)BrucePay commentedon Mar 3, 2017
PowerShell remoting uses it's own serialization mechanism as described in protocol specification MS-PSRP, section 2.2.5. By design, a limited, fixed set of types deserialize with fidelity. This list is available in MS-PSRP section 2.2.5.1 (see https://msdn.microsoft.com/en-us/library/dd305931.aspx )
Adding support for new primitive types requires changes to both the code/protocol and protocol specifications. The serialization code is in
src\System.Management.Automation\engine\Serialization.cs
src\System.Management.Automation\engine\SerializationStrings.cs
(Note: you can use the types files and Update-TypeData to specify custom deserializations in the local runspace but these need to be set up in each session.)
For PowerShell 6.0, it seems reasonable that we expand the set of types we serialize with fidelity but we should do this deliberately. I suggest opening an RFC for this so we can get a canonical list of the new types we want to handle.
iSazonov commentedon Oct 8, 2017
Can we implement a generic algorithm based on a schema to being more flexible?
Jaykul commentedon Feb 2, 2022
I don't understand why this is taking years. How hard is this?
Can't you just write a converter like this DateTimeOffsetConverter and register it for DateTimeOffset?
PaulHigin commentedon Apr 7, 2022
@WG-Remoting
Remoting working group: Adding new remoting types requires updating the remoting protocol version and associated documents, which is a very large work item. It is unlikely that we would do this just for a single new type, but this could be part of a planned protocol upgrade that encompasses many enhancements. There is currently no plan to do this, but in the meantime, types can be deserialized into concrete types using PowerShell's extended type system over remoting.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
wbuck commentedon Feb 13, 2024
How can I work around this issue? When call a powershell script via a
C#application I'm getting an exception regarding mismatched types:System.DateTimeOffsetvsDeserialized.DateTimeOffset.