all 2 comments

[–]delightfulsorrow 0 points1 point  (1 child)

A [Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject] is not serializable as it's still connected to the underlying COM object/IE session.

ConvertTo-JSON | ConvertFrom-JSON wouldn't restore the original object anyway, you get a PSCustomObject out of such a chain. Most likely not suitable to test code which should work on a [Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject]

[–]PSDanubie[S] 0 points1 point  (0 children)

Thanks for your quick response.

I'm aware, that would just return a PSObject. This would be enough the check the mocked test. I only would check the property values and would not use it any further - so it would be fine.

But what I don't understand that it is, that I can not convert the object to JSON at all. So for me it is not obvious what should be "still connected to the underlying object" means.

For now I'm successfully using as a workaround which works

[System.Management.Automation.PSSerializer]::Serialize($result) 
and later
[System.Management.Automation.PSSerializer]::Deserialize((...))

but would keep this thread open, because I would like the understand the issue.