Skip to content

Commit b86f77c

Browse files
author
shipra
committed
Handling Json deserialization error
1 parent 9a5ea29 commit b86f77c

File tree

1 file changed

+16
-1
lines changed
  • src/ResourceManager/Automation/Commands.Automation/Model

1 file changed

+16
-1
lines changed

src/ResourceManager/Automation/Commands.Automation/Model/Job.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Automation.Model
2123
{
@@ -65,7 +67,20 @@ public Job(string resourceGroupName, string accountName, Azure.Management.Automa
6567
if (0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) &&
6668
0 != String.Compare(kvp.Key, Constants.JobRunOnParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
6769
{
68-
this.JobParameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
70+
object paramValue;
71+
try
72+
{
73+
paramValue = ((object) PowerShellJsonConverter.Deserialize(kvp.Value));
74+
}
75+
catch (CmdletInvocationException exception)
76+
{
77+
if (!exception.Message.Contains("Invalid JSON primitive"))
78+
throw;
79+
80+
paramValue = kvp.Value;
81+
}
82+
this.JobParameters.Add(kvp.Key, paramValue);
83+
6984
}
7085
}
7186
}

0 commit comments

Comments
 (0)