Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type

In this Azure PowerShell article, we will discuss how to fix the error “unable to cast object of type ‘newtonsoft.json.linq.jvalue’ to type ‘newtonsoft.json.linq.jobject'” which I got while trying to create a new resource management group in Azure using the New-AzManagementGroup PowerShell command.

Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type

I had a requirement to create an Azure management group using the New-AzManagementGroup command. So, I was trying to execute the below PowerShell command.

PS C:\WINDOWS\system32> New-AzManagementGroup -GroupName "TsinfoGroup"

I got the below output when I ran the above PowerShell command.

New-AzManagementGroup : Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' 
to type 'Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup'.
At line:1 char:1
+ New-AzManagementGroup -GroupName "TsinfoGroup"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzManagementGroup], InvalidCastExc 
   eption
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.ManagementGroups.New 
   AzureRmManagementGroup

You ca n see the same error in the below screen shot.

unable to cast object of type 'newtonsoft.json.linq.jobject' to type

Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type [Solution]

To solve this issue, we need to use the “GroupId” parameter instead of the “GroupName” parameter. So, we need to execute the below PowerShell script to create the management group in Azure.

PS C:\WINDOWS\system32> New-AzManagementGroup -GroupId "TsinfoGroup"

After executing the above command, I got the correct output, and the management group was created successfully in seconds. You can see the output in the screenshot below.

unable to cast object of type 'newtonsoft.json.linq.jvalue' to type 'newtonsoft.json.linq.jobject

You may also like following the articles below

Conclusion

In this Azure PowerShell article, we discussed how to fix the error “unable to cast object of type ‘newtonsoft.json.linq.jvalue’ to type ‘newtonsoft.json.linq.jobject’.” Thanks for reading this article !!!