Skip to content

How do we customize serialization? #3173

Closed

Description

@Jaykul

There was a PowerShell Team blog post years ago about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I haven't been able to make extending the serialization work. If someone can help me figure this out, I'll make sure we get a HowTo document for future module authors out of it ...

I'm going to use a simple example, but remember that I'm looking for the way to make Deserialization work properly -- I don't want to hear about all the workarounds for this particular case (there are several). The real problem I'm trying to solve is more complicated.

I need to call a remote function which takes a DateTimeOffset object, Unlike DateTime, DateTimeOffest isn't treated as a primitive type (although it should be #3172), so I want to fix that in my module.

Here's what I tried:

using namespace System.Management.Automation

class DateTimeOffsetDeserializer : System.Management.Automation.PSTypeConverter {

    [bool] CanConvertFrom([object]$sourceValue, [Type]$destinationType)
    {
        Write-Warning "CanConvertFrom $SourceValue to $($destinationType.FullName)"
        return ([PSObject]$sourceValue).PSTypeNames.Contains("Deserialized.System.DateTimeOffset")
    }

    [object] ConvertFrom([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
    {
        Write-Warning "ConvertFrom $SourceValue to $($destinationType.FullName)"
        [PSObject]$psSourceValue = $sourceValue
        return [DateTimeOffset]::new($psSourceValue.Ticks, $psSourceValue.Offset)
    }

    [bool] CanConvertTo([object]$sourceValue, [Type]$destinationType)
    {
        Write-Warning "CanConvertTo $SourceValue to $($destinationType.FullName)"
        return ([PSObject]$sourceValue).PSTypeNames.Contains("Deserialized.System.DateTimeOffset") -and $destinationType -eq "System.DateTimeOffset"
    }

    [object] ConvertTo([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
    {
        Write-Warning "ConvertTo $SourceValue to $($destinationType.FullName)"
        [PSObject]$psSourceValue = $sourceValue
        return [DateTimeOffset]::new($psSourceValue.Ticks, $psSourceValue.Offset)
    }
}

# This should be enough, right?
Update-TypeData -TypeName 'DateTimeOffset' -TargetTypeForDeserialization 'DateTimeOffsetDeserializer' -Force

# I tried adding all the rest of these
Update-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -TargetTypeForDeserialization 'DateTimeOffsetDeserializer' -Force
Update-TypeData -TypeName 'DateTimeOffset' -MemberName 'TargetTypeForDeserialization' -MemberType 'NoteProperty' -Value 'DateTimeOffsetDeserializer'
Update-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -MemberName 'TargetTypeForDeserialization' -MemberType 'NoteProperty' -Value 'DateTimeOffsetDeserializer'

But nothing makes the this come out as a DateTimeOffset

using namespace System.Management.Automation
[PSSerializer]::Deserialize( [PSSerializer]::Serialize([DateTimeOffset]::Now) ).PSTypeNames

Or make this not be "Deserialized"

Invoke-Command -ComputerName localhost { [DateTimeOffset]::Now } | % PSTypeNames

Or make this run without crashing:

Invoke-Command -ComputerName localhost { param([DateTimeOffset]$Time) $Time.LocalDateTime } -Args ([DateTimeOffset]::Now)

I also tried creating the DateTimeOffsetDeserializer class in C#, but I think I'm misunderstanding that original blog post or something about how the registration works...

Activity

  1. Jaykul commented on Feb 22, 2017

    @Jaykul
    ContributorAuthor

    Ok, after three days of trying ... I finally thought of searching through all of GitHub for use of TargetTypeForDeserialization and came across the solution. The TypeData needs to be like this:

    Register the TargetType for the Deserialized type:

    Update-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -TargetTypeForDeserialization 'System.DateTimeOffset'

    Then register the TypeConverter for that TargetType:

    Update-TypeData -TypeName 'System.DateTimeOffset' -TypeConverter 'DateTimeOffsetDeserializer'

    This is the part that was completely skipped over in the blog post -- if anyone can add a couple of lines to that post, that would be great! 😉

    You can, of course, do all of this in a Types.ps1xml instead:

    <?xml version="1.0" encoding="utf-8" ?>
    <Types>
        <Type>
            <Name>System.DateTimeOffset</Name>
            <TypeConverter>
                <TypeName>DateTimeOffsetDeserializer</TypeName>
            </TypeConverter>
            <Members>
                <MemberSet>
                    <Name>PSStandardMembers</Name>
                    <Members>
                        <NoteProperty>
                            <Name>SerializationDepth</Name>
                            <Value>1</Value>
                        </NoteProperty>
                    </Members>
                </MemberSet>
            </Members>
        </Type>
        <Type>
            <Name>Deserialized.System.DateTimeOffset</Name>
            <Members>
                <MemberSet>
                    <Name>PSStandardMembers</Name>
                    <Members>
                        <NoteProperty>
                            <Name>TargetTypeForDeserialization</Name>
                            <Value>System.DateTimeOffset</Value>
                        </NoteProperty>
                    </Members>
                </MemberSet>
            </Members>
        </Type>
    </Types>

    I should note (because I haven't tested this on PowerShell 3 or 4): the explanation in the SDK makes this somewhat more convoluted -- rather than specifying the actual target type as the TargetTypeForDeserialization, they state that you should specify the Deserializer as the TargetTypeForDeserialization (i.e. in place of System.DateTimeOffset above), which means that you need an extra call (or <Type> entry) to set the SerializationDepth ....

    That makes no sense to me, but perhaps it's actually necessary for some situations or older versions of PowerShell.

  2. iSazonov commented on Feb 22, 2017

    @iSazonov
    Collaborator
  3. Jaykul commented on Feb 22, 2017

    @Jaykul
    ContributorAuthor

    It turns out, there's a different problem: this does not work for PowerShell classes.

    Take this simple case for example:

    class Test {
        [string]$FirstName
        [string]$LastName
        [string]$FullName
    
        Test([string]$FirstName, [string]$LastName) {
            $this.FirstName = $FirstName
            $this.LastName = $LastName
            $this.FullName = $FirstName + " " + $LastName
        }
    }

    Because it has a custom constructor, you need a custom converter.

    To hide some of the sillyness of this, I like to use an intermediate PSObjectConverter:

    # A do-nothing converter, just to hide the "object" methods
    class PSObjectConverter : System.Management.Automation.PSTypeConverter
    {
        [bool] CanConvertFrom([PSObject]$psSourceValue, [Type]$destinationType)
        {
            return $false
        }
    
        [object] ConvertFrom([PSObject]$psSourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
        {
            throw [NotImplementedException]::new()        
        }
    
        # These things down here are just never used. Why they must be here, I have no idea.
        [bool] CanConvertFrom([object]$sourceValue, [Type]$destinationType)
        {
            return $false;
        }
    
        [object] ConvertFrom([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
        {
            throw [NotImplementedException]::new();
        }
    
        [bool] CanConvertTo([object]$sourceValue, [Type]$destinationType)
        {
            throw [NotImplementedException]::new();
        }
    
        [object] ConvertTo([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
        {
            throw [NotImplementedException]::new();
        }
    }
    
    
    class TestConverter : PSObjectConverter
    {
        [bool] CanConvertFrom([PSObject]$psSourceValue, [Type]$destinationType)
        {
            Write-Warning "CanConvertFrom $($psSourceValue.PSTypeNames)"
            return $psSourceValue.PSTypeNames.Contains("Deserialized.Test")
        }
    
        [object] ConvertFrom([PSObject]$psSourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
        {
            Write-Warning "ConvertFrom $($psSourceValue.PSTypeNames)"
            Write-Warning "So there can be no doubt this does not work:"
            Write-Warning ("[Test]::new('" + $psSourceValue.FirstName + "', '" + $psSourceValue.LastName + "')")
            $Converted = [Test]::new($psSourceValue.FirstName, $psSourceValue.LastName)
            Write-Warning "REMOTE EXECUTION NEVER REACHES THIS LINE"
            return $Converted
        }
    }
    

    Finally, register the serialization:

    Update-TypeData -TypeName 'Deserialized.Test' -TargetTypeForDeserialization 'Test'
    Update-TypeData -TypeName 'Test' -TypeConverter 'TestConverter'

    Now, test it. Locally, it works fine:

    > using namespace System.Management.Automation
    >  [PSSerializer]::Deserialize( [PSSerializer]::Serialize( [Test]::new("Joel","Bennett")  ) )
    
    WARNING: CanConvertFrom Deserialized.Test Deserialized.System.Object
    WARNING: ConvertFrom Deserialized.Test Deserialized.System.Object
    WARNING: So there can be no doubt this does not work:
    WARNING: [Test]::new('Joel', 'Bennett')
    WARNING: REMOTE EXECUTION NEVER REACHES THIS LINE
    
    FirstName LastName FullName
    --------- -------- --------
    Joel      Bennett  Joel Bennett

    But when I try to run the command remotely, it just hangs?

    Invoke-Command -ComputerName localhost {
        "Hello from ${Env:ComputerName}, I got $($args.ForEach{$_.PSTypeNames[0]}) and I'm going to send them back to you:"
        $args
        "Goodbye!"
    } -Args ( [Test]::new("Joel","Bennett") )
    Hello from USTWL-JOELB, I got Deserialized.Test and I'm going to send them back to you:
    WARNING: CanConvertFrom Deserialized.Test Deserialized.System.Object
    WARNING: ConvertFrom Deserialized.Test Deserialized.System.Object
    WARNING: So there can be no doubt this does not work:
    WARNING: [Test]::new('Joel', 'Bennett')
    

    Jason Shirk (@lzybkr) Is this just not possible?

  4. lzybkr commented on Feb 23, 2017

    @lzybkr
    Contributor

    Thanks for the excellent repro.

    Getting this scenario to work might be tricky.

    Scriptblocks have runspace affinity. Class methods are really just scriptblocks, they get runspace affinity too. I think this is an architectural flaw, but it's not easy to fix without requiring locks throughout the engine.

    In this repro - there is only 1 local runspace. The deserialization is happening on a thread with no runspace and it's waiting for the Invoke-Command runspace (the only local runspace, the runspace where the module was imported) to become available to run commands.

    One fix would be to not block in Invoke-Command - instead timeout and poll for events.

  5. added
    WG-Engine
    WG-Remoting
    Issue-Bug
    on Feb 23, 2017
  6. Jaykul commented on Feb 23, 2017

    @Jaykul
    ContributorAuthor

    Thanks. I'll just ... write those classes in C# I guess. But I guess we need to document that you can write C# classes and PowerShell converters but not both in PowerShell, and not PowerShell classes with C# converters (I guess).

  7. Brain2000 commented on Dec 20, 2018

    @Brain2000

    This is certainly not complete, but will at least let you copy over the class definition and properties to a PSSession. Maybe someone can add methods/constructors...

    class test
    {
      [string]$abc;
      [string]$def;
    }
    
    function getClassDef
    {
    	[OutputType([string])]
    	param (
    		[Parameter(Mandatory=$true)][Type]$classType
    	)
    
    	$create = "class $($classType.Name)`r`n{`r`n ";
    	$create += $classType.GetProperties() | ForEach-Object { "   [$($_.PropertyType.ToString())]`$$($_.Name)`r`n"; }
    	$create += "}";
    
    	return $create;
    }
    
    $def = getClassDef([test]);
    $s = New-PSSession someRemoteComputer
    Invoke-Command $s { Invoke-Expression $Using:def } #this creates the class remotely
    
    #now run a test
    Invoke-Command $s { $t = [test]::new(); $t; }
    
    
    
  8. SSvilen commented on Jun 10, 2019

    @SSvilen

    Hi Paul Higinbotham (@PaulHigin) - we were discussing the topic of object's rehydration after your session about remoting at PSConfEu. You suggested me to open an issue, so that you can discuss that internally and may be do a blog post about it. It seems that this is not a new topic - so I'll use that issue here as reminder. Thanks to Joel Bennett (@Jaykul) I have something to work with, but may be new blog post about this topic would be a good start

  9. PaulHigin commented on Jun 18, 2019

    @PaulHigin
    Contributor

    Svilen (@SSvilen) Thanks, I am back in office now. I am glad that this helps, but as we discussed this is really something that should be addressed in a blog. I'll try to do so in the not too distant future.

  10. kenny1983 commented on Oct 20, 2019

    @kenny1983

    Hi guys, just wondering whether there's been any new developments on this issue in the past 4 months, as I'm trying to get the following script working:

    class PSProvisioner {
        [Management.Automation.PSCredential] $Credential
        [Management.Automation.Runspaces.PSSession] $Session
    
        [TimeSpan] $TotalTime
    
        PSProvisioner() {
            $this.Credential = ([Management.Automation.PSCredential]::new(`
                "vagrant", $(ConvertTo-SecureString "vagrant" -AsPlainText -Force)))
            $this.Session = New-PSSession -ComputerName 192.168.15.11 `
                -Port 55985 -Credential $this.Credential
        }
    
        [void] PrintHeader([string] $header) {
            Write-Host $header
            ...Do some other stuff
        }
    
        [void] Test([PSProvisioner] $inst) {
            Invoke-Command -Session $this.Session -ScriptBlock {
                ($Using:inst).PrintHeader("This is a test!")
            }
        }
    }
    
    $provisioner = [PSProvisioner]::new()
    $provisioner.Test($provisioner)
    

    Which throws the following error:

    Method invocation failed because [Deserialized.PSProvisioner] does not contain a method named 'PrintHeader'.
    At D:\Dev\MutatioDev\provision-guest.ps1:393 char:9
    +         Invoke-Command -Session $this.Session -ScriptBlock {
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (PrintHeader:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
    

    Would absolutely adore some guidance on how to get this to work, if it's at all possible. In the meantime, I guess I'll have to go back to using scripts 🙁 MTIA!

  11. Kagre commented on Mar 10, 2021

    @Kagre

    I'm not sure if it's related or not, but there also appears to be a scoping issue with -TargetTypeForDeserialization

    .{ #<--- Write-Warning's do not show when run inside this scope, & likewise
    class Test {
        [string]$FirstName
        [string]$LastName
        [string]$FullName
    
        Test([string]$FirstName, [string]$LastName) {
            $this.FirstName = $FirstName
            $this.LastName = $LastName
            $this.FullName = $FirstName + " " + $LastName
        }
    }
    
    # Minifiy: A do-nothing converter, just to hide the "object" methods
    class PSObjectConverter : System.Management.Automation.PSTypeConverter{
      [bool]   CanConvertFrom([PSObject]$psSourceValue, [Type]$destinationType){
        return $false}
      [object] ConvertFrom([PSObject]$psSourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase){
        throw [NotImplementedException]::new()}
    
      # These things down here are just never used. Why they must be here, I have no idea.
      [bool]   CanConvertFrom([object]$sourceValue, [Type]$destinationType){
        return $false;}
      [object] ConvertFrom([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase){
        throw [NotImplementedException]::new();}
      [bool]   CanConvertTo([object]$sourceValue, [Type]$destinationType){
        throw [NotImplementedException]::new();}
      [object] ConvertTo([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase){
        throw [NotImplementedException]::new();}
    }
    
    class TestConverter : PSObjectConverter
    {
        [bool] CanConvertFrom([PSObject]$psSourceValue, [Type]$destinationType)
        {
            Write-Warning "CanConvertFrom $($psSourceValue.PSTypeNames)"
            return $psSourceValue.PSTypeNames.Contains("Deserialized.Test")
        }
    
        [object] ConvertFrom([PSObject]$psSourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)
        {
            Write-Warning "ConvertFrom $($psSourceValue.PSTypeNames)"
            Write-Warning "So there can be no doubt this does not work:"
            Write-Warning ("[Test]::new('" + $psSourceValue.FirstName + "', '" + $psSourceValue.LastName + "')")
            $Converted = [Test]::new($psSourceValue.FirstName, $psSourceValue.LastName)
            Write-Warning "REMOTE EXECUTION NEVER REACHES THIS LINE"
            return $Converted
        }
    }
    
    Update-TypeData -TypeName 'Deserialized.Test' -TargetTypeForDeserialization 'Test'
    Update-TypeData -TypeName 'Test' -TypeConverter 'TestConverter'
    
    ($result = [System.Management.Automation.PSSerializer]::Deserialize( 
      [System.Management.Automation.PSSerializer]::Serialize( 
        [Test]::new("Joel","Bennett")  ) ))
        
    get-member -InputObject $result | out-string | write-host -ForegroundColor DarkCyan
    }

    Otherwise Jobs would have been nice

    #UsingExample.ps1
    . ($Def = {
       class MyObject{
          [int]$Value
          
          MyObject(){
             $this.Value = 0
          }
    
          MyObject($v){
             $this.Value = $v
          }
          
          [void] inc(){
             $null = $this.Value++
          }
       }
    
       class MyObjectDeserializer : System.Management.Automation.PSTypeConverter {
          [bool] CanConvertFrom([object]$ObjToCast, [Type]$ToType) {
             return $ToType -eq [MyObject]
          }
    
          [object] ConvertFrom([object]$ObjToCast, [Type]$ToType, [IFormatProvider]$formatProvider, [bool]$ignoreCase) {
             try{return [MyObject]::new(($ObjToCast.Value))}catch {
                throw ([System.InvalidCastException]"Unknown Value: $($ObjToCast.Value)")
             }
          }
    
          ################# Not used by PowerShell? ##############################################################
          [bool] CanConvertTo([object]$Value, [Type]$ToType){                                                    #
             throw [System.NotImplementedException]::new(                                                        #
                "CanConvertTo([Object]'$Value', [Type]'$ToType')")}                                              #
          [object] ConvertTo([object]$Value, [Type]$ToType, [IFormatProvider]$formatProvider, [bool]$ignoreCase){#
             throw [System.NotImplementedException]::new(                                                        #
                "ConvertTo([Object]'$Value', [Type]'$ToType', [IFormatProvider], [bool]'$ignoreCase')")}         #
          ########################################################################################################
       }
       Update-TypeData -TypeName MyObject -TypeConverter 'MyObjectDeserializer'
       Update-TypeData -TypeName 'Deserialized.MyObject' -TargetTypeForDeserialization MyObject
    })
    
    $obj = [MyObject]::new()
    
    $pss = [System.Management.Automation.PSSerializer]
    $dsObj = $pss::Deserialize($pss::Serialize($Obj))
    
    $wk1 = start-job -Name 'UsingExample\Worker1' -InitializationScript $Def -ScriptBlock {
       $o = $using:obj
       gm -InputObject $o
       
       $o = [MyObject]$o # <--- Why doesn't it Auto-Rehydrate?
       
       $o.inc()
       $o.value
    }
    start-sleep 2
    receive-job $wk1
    remove-job $wk1
  12. Kagre commented on Mar 10, 2021

    @Kagre

    Never mind -TargetTypeForDeserialization appears to be "working as designed", and so too is the localized randomization of class type names.

    After mucking about with the localized class naming and the timing of the deserialization declaration, I've finally got the Jobs --if not elegant-- at least working (I'll leave the Invoke-Command, re-rehydration(bihydration?) of a job returned deserialized object, and code cleanup to someone else):

    #UsingExample.ps1
    . ($Def = {
       class MyObject{
          [int]$Value
          
          MyObject(){
             $this.Value = 0
          }
    
          MyObject($v){
             $this.Value = $v
          }
          
          [void] inc(){
             $null = $this.Value++
          }
       }
    
       class MyObjectDeserializer : System.Management.Automation.PSTypeConverter {
          static [string]$DSTypeName = ''
          
          [bool] CanConvertFrom([object]$ObjToCast, [Type]$ToType) {
             write-host "CanConvert: from $($ObjToCast.PSTypeNames[0]) to $ToType" -ForegroundColor DarkCyan
             write-host "Looking for: $($this::DSTypeName)" -ForegroundColor Yellow -BackgroundColor Black
             $ObjToCast.PSTypeNames | out-string | write-host  -ForegroundColor Yellow -BackgroundColor Black
             $ObjToCast.PSTypeNames.Contains($this::DSTypeName) | write-host  -ForegroundColor Yellow -BackgroundColor Black
             return $ToType -eq [MyObject] -and (
                $ObjToCast.PSTypeNames.Contains($this::DSTypeName) -or
                $ObjToCast.PSTypeNames.Contains('Deserialized.MyObject')
             )
          }
    
          [object] ConvertFrom([object]$ObjToCast, [Type]$ToType, [IFormatProvider]$formatProvider, [bool]$ignoreCase) {
             write-host "ConvertFrom: from $($ObjToCast.PSTypeNames[0]) to $ToType" -ForegroundColor DarkCyan
             try{return [MyObject]::new(($ObjToCast.Value))}catch {
                throw ([System.InvalidCastException]"Unknown Value: $($ObjToCast.Value)")
             }
          }
    
          ################# Not used by PowerShell? ##############################################################
          [bool] CanConvertTo([object]$Value, [Type]$ToType){                                                    #
             throw [System.NotImplementedException]::new(                                                        #
                "CanConvertTo([Object]'$Value', [Type]'$ToType')")}                                              #
          [object] ConvertTo([object]$Value, [Type]$ToType, [IFormatProvider]$formatProvider, [bool]$ignoreCase){#
             throw [System.NotImplementedException]::new(                                                        #
                "ConvertTo([Object]'$Value', [Type]'$ToType', [IFormatProvider], [bool]'$ignoreCase')")}         #
          ########################################################################################################
       }
       $psz = [System.Management.Automation.PSSerializer]
       $o = [MyObject]::New(0)
       $dso = $psz::Deserialize($psz::Serialize($o))
       $LocalDSTypeName = $dso.PSTypeNames[0]
       [MyObjectDeserializer]::DSTypeName = $LocalDSTypeName
    
       Update-TypeData -TypeName MyObject -TypeConverter 'MyObjectDeserializer'
       Update-TypeData -TypeName 'Deserialized.MyObject' -TargetTypeForDeserialization MyObject
       if($LocalDSTypeName -ne 'Deserialized.MyObject'){
          Update-TypeData -TypeName $LocalDSTypeName -TargetTypeForDeserialization MyObject
       }
       rv o,dso
    })
    $JobDef = {
       [MyObjectDeserializer]::DSTypeName = '$LocalDSTypeName'
       Update-TypeData -TypeName '$LocalDSTypeName' -TargetTypeForDeserialization MyObject -ErrorAction SilentlyContinue
    }
    $JobDef = [ScriptBlock]::Create(($Def.ToString()+ $JobDef.ToString().replace('$LocalDSTypeName',$LocalDSTypeName)))
    
    $obj = [MyObject]::new()
    $obj.inc()
    
    write-host 'Local: Expected auto-cast by deserialization rehydration' -ForegroundColor Magenta
    $dsObj = $psz::Deserialize($psz::Serialize($Obj))
    ($x = ((get-member -InputObject $dsObj)[0].TypeName)) | write-warning
    
    $wk1 = start-job -Name 'UsingExample\Worker1' -InitializationScript $JobDef -ScriptBlock {
    #   [MyObjectDeserializer]::DSTypeName = $using:LocalDSTypeName
    #   Update-TypeData -TypeName $using:LocalDSTypeName -TargetTypeForDeserialization MyObject
       
       write-host "`nJob: Expected implicit cast by auto-deserialization rehydration" -ForegroundColor Magenta
       $o = $using:obj # <--- Why doesn't it Auto-Rehydrate? Yay, if finally works
       $o.PSTypeNames | out-string | write-host
       #$o.inc()
       
       write-host "`nJob: Explicit cast to [MyObject]" -ForegroundColor Magenta
       $o = [MyObject]$o
       $o.inc()
       
       write-host "`nJob: localized explicit rehydration" -ForegroundColor Magenta
       $oo = [MyObject]::new()
       $dsoo = $psz::Deserialize($psz::Serialize($oo))
       $dsoo.PSTypeNames | out-string | write-host
    
       $o.Value
    }
    wait-job -job $wk1 -Timeout 60
    receive-job $wk1
    remove-job $wk1
    
    
    <#
    $s = new-pssession 'server'
    invoke-command -Session $s -ScriptBlock $def
    invoke-command -Session $s -ScriptBlock {
       "hello from ${Env:ComputerName}, I got $()"
    } -
    #>
  13. 1ramnik commented on Mar 10, 2021

    @1ramnik

    what is the meaning of stream of bytes?
    Please explain a bit.

  14. Kagre commented on Mar 10, 2021

    @Kagre

    what is the meaning of stream of bytes?
    Please explain a bit.

    where are you seeing a "stream of bytes"?

  15. Kagre commented on Mar 10, 2021

    @Kagre

    re-rehydration(bihydration?) of a job's returned deserialized object

    byedration

  16. Stroniax commented on Jul 12, 2023

    @Stroniax
    Update-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -TargetTypeForDeserialization 'System.DateTimeOffset'

    Then register the TypeConverter for that TargetType:

    Update-TypeData -TypeName 'System.DateTimeOffset' -TypeConverter 'DateTimeOffsetDeserializer'

    This is the part that was completely skipped over in the blog post -- if anyone can add a couple of lines to that post, that would be great! 😉

    This doesn't add up. The example in the blog refers to the IP address conversion. If you look at the type data of System.Net.IPAddress and Deserialized.System.Net.IPAddress, the data matches up with the instructions provided in the blog. However I am likewise not able to get this to work that way.

  17. added
    Resolution-No Activity
    on Jan 9, 2024
  18. microsoft-github-policy-service commented on Jan 9, 2024

    @microsoft-github-policy-service
    Contributor

    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.

  19. microsoft-github-policy-service commented on Jan 9, 2024

    @microsoft-github-policy-service
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-No ActivityWG-EngineWG-Remoting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions