Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization converts JsonString to Object #773

Closed
snerte opened this issue Mar 4, 2022 · 4 comments
Closed

Deserialization converts JsonString to Object #773

snerte opened this issue Mar 4, 2022 · 4 comments

Comments

@snerte
Copy link

snerte commented Mar 4, 2022

Reproduction steps

I am experiencing this issue while calling an Invoke-ActivityFunction from an orchestration function. I have taken control over serialization and deserialization.

Orchestrator:

    $jsonInput = [PSCustomObject]@{
        Result = $_
        (...)
    } | ConvertTo-Json -Depth 5

    Write-Host "Calling ActivityFunction with: $($jsonInput)"

    [PSCustomObject]@{
        Result = $_
        Task   = Invoke-ActivityFunction -FunctionName 'ActivityFunction' -Input $jsonInput -NoWait
    }

Output from Write-Host in Orchestrator:

INFORMATION: Calling ActivityFunction with: { (...) some long JSON string }

So I know my deserialization works.

ActivityFunction:

param(
    [Parameter(Mandatory)]
    [string]
    $InputData)

Write-Host "ActivityFunction: Got JSON input $InputData"

$InputData = $InputData | ConvertFrom-Json

Current behaviour

My Write-Host in ActivityFunction outputs: INFORMATION: SaveCustomerEnvironmentCheckResult: Got JSON input System.Collections.Hashtable.

From the serialization I get this exception, which makes sense if the value is not valid JSON:

EXCEPTION: Conversion from JSON failed with error: Unexpected character encountered while parsing value: S. Path '', line 0, position 0. Exception : Type : System.ArgumentException Message : Conversion from JSON failed with error: Unexpected character encountered while parsing value: S. Path '', line 0, position 0. TargetSite : Name : ConvertFromJson DeclaringType : Microsoft.PowerShell.Commands.JsonObject MemberType : Method Module : Microsoft.PowerShell.Commands.Utility.dll StackTrace : at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, Boolean returnHashtable, Nullable`1 maxDepth, ErrorRecord& error) at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.EndProcessing() at System.Management.Automation.Cmdlet.DoEndProcessing() at System.Management.Automation.CommandProcessorBase.Complete() InnerException : Type : Newtonsoft.Json.JsonReaderException TargetSite : Name : ParseValue DeclaringType : Newtonsoft.Json.JsonTextReader MemberType : Method Module : Newtonsoft.Json.dll StackTrace : at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.Read() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, Boolean returnHashtable, Nullable`1 maxDepth, ErrorRecord& error) Message : Unexpected character encountered while parsing value: S. Path '', line 0, position 0. Source : Newtonsoft.Json HResult : -2146233088 Source : Microsoft.PowerShell.Commands.Utility HResult : -2147024809 CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand InvocationInfo : MyCommand : ConvertFrom-Json ScriptLineNumber : 13 OffsetInLine : 27 HistoryId : 1 ScriptName : C:\home\site\wwwroot\SaveCustomerEnvironmentCheckResult\run.ps1 Line : $InputData = $InputData | ConvertFrom-Json PositionMessage : At C:\home\site\wwwroot\SaveCustomerEnvironmentCheckResult\run.ps1:13 char:27 + $InputData = $InputData | ConvertFrom-Json + ~~~~~~~~~~~~~~~~ PSScriptRoot : C:\home\site\wwwroot\SaveCustomerEnvironmentCheckResult PSCommandPath : C:\home\site\wwwroot\SaveCustomerEnvironmentCheckResult\run.ps1 InvocationName : ConvertFrom-Json CommandOrigin : Internal ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\SaveCustomerEnvironmentCheckResult\run.ps1: line 13 PipelineIterationInfo :

Expected behaviour

My Write-Host in ActivityFunction outputs: INFORMATION: SaveCustomerEnvironmentCheckResult: Got JSON input { (...) some long JSON string }.

Originally posted by @snerte in Azure/azure-functions-durable-extension#1922 (comment)

@snerte snerte changed the title Deserialization converts JsonString containing JsonString to Object Deserialization converts JsonString to Object Mar 4, 2022
@cgillum
Copy link

cgillum commented Mar 7, 2022

@davidmrdavid or @AnatoliB would either of you be able to move this to the appropriate PowerShell repository and triage accordingly?

@AnatoliB AnatoliB transferred this issue from Azure/azure-functions-durable-extension Mar 7, 2022
@davidmrdavid
Copy link
Contributor

Thanks @cgillum. As I've noted in another thread - this is a known problem in the Durable Functions for PowerShell SDK, but unfortunately we can't fix it without introducing a breaking change. I have fixed this in the code for our next major release, which we're currently preparing. I can't give an exact estimate for when this will be out, but if everything goes well it shouldn't be more than a handful of months.

@AnatoliB
Copy link
Contributor

AnatoliB commented May 3, 2022

@snerte Could you please post the content of your $jsonInput, so that we can reproduce the issue? Thank you.

@ghost
Copy link

ghost commented May 7, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost ghost closed this as completed May 11, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants