首页 > 系统相关 >PowerShell 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been excee

PowerShell 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been excee

时间:2023-11-08 21:32:21浏览次数:28  
标签:Function Newtonsoft JsonReaderException exceeded Json Context reader AzStorageAc

问题描述

创建PowerShell Azure Durable Function,执行大量的PowerShell脚本操作Azure Resource,遇见了一个非常非常奇怪的问题:

Function 'Hello1 (Activity)' failed with an error. Reason: Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded. Path '[9].Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.StorageAccount.BlobStorageUri', line 1, position 103037.

at Newtonsoft.Json.JsonReader.Push(JsonContainerType value)

at Newtonsoft.Json.JsonTextReader.ParseValue()

at Newtonsoft.Json.JsonWriter.WriteToken(JsonReader reader, Boolean writeChildren, Boolean writeDateConstructorAsDate, Boolean writeComments)

at Newtonsoft.Json.Linq.JTokenWriter.WriteToken(JsonReader reader, Boolean writeChildren, Boolean writeDateConstructorAsDate, Boolean writeComments)

Stack: .

PowerShell 函数遇见 Newtonsoft.Json.JsonReaderException: The reader

 

问题解答

Function 'Hello1 (Activity)' failed with an error. Reason: Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded. 
Path '[9].Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
Context.Context.Context.Context.Context.Context.Context.Context.Context.Context.
StorageAccount.BlobStorageUri', line 1, position 103037.

at Newtonsoft.Json.JsonReader.Push(JsonContainerType value)

因为异常中的Stack并没有指明是那一句代码引起的异常,所以只好使用最笨的办法。

一行代码一行代码的调试。

PowerShell 函数遇见 Newtonsoft.Json.JsonReaderException: The reader

最终,在对代码进行逐句逐句的注释后执行,定位到是 New-AzStorageAccount的问题。当注释掉这一句后,问题消失。

New-AzStorageAccount -ResourceGroupName $rgName -Name $storageName -SkuName Standard_LRS -Location $region -AllowBlobPublicAccess $false  

 但是,为什么它会导致Function App执行出现如此诡异的问题呢?

 

问题原因

PowerShell 函数遇见 Newtonsoft.Json.JsonReaderException: The reader

(单独执行 New-AzStorageAccount 代码,发现它的输出信息为一个表格对象)

Durable Function会把执行的输出进行转换为JSON Object并保存在Activity 函数的日志中。

因为Function Runtime在转换这个对象时,触发了Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded. 异常。 就是这个对象的深度达到了JSON的最大深度64。

解决办法

基于问题原因,可以主动修改New-AzStorageAccount 的结果输出,可以把输出到文件中,或者转换为 JSON格式,来避免问题。

方式一:把输出信息保存为文件,在命令后加上*> script.log

New-AzStorageAccount -ResourceGroupName $rgName -Name $storageName -SkuName Standard_LRS -Location $region -AllowBlobPublicAccess $false    *> script.log

 

方式二:把输出对象转换为JSON, 在命令后加上| ConvertTo-Json

New-AzStorageAccount -ResourceGroupName $rgName -Name $storageName -SkuName Standard_LRS -Location $region -AllowBlobPublicAccess $false    | ConvertTo-Json

 

经测试,两种方式都可以解决问题。

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

标签:Function,Newtonsoft,JsonReaderException,exceeded,Json,Context,reader,AzStorageAc
From: https://blog.51cto.com/u_13773780/8259431

相关文章

  • 【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReade
    问题描述创建PowerShellAzureDurableFunction,执行大量的PowerShell脚本操作AzureResource,遇见了一个非常非常奇怪的问题:Function'Hello1(Activity)'failedwithanerror.Reason:Newtonsoft.Json.JsonReaderException:Thereader'sMaxDepthof64hasbeenexceeded.......
  • Newtonsoft.Json基本用法
    序列化和反序列化JSONJsonConvert对于想要与JSON字符串相互转换的简单场景,JsonConvert上的SerializeObject ()和 DeserializeObject () 方法在JsonSerializer上提供了易于使用的包装器。下面代码使用序列化与反序列化:1classProduct2{3[JsonIgnore]4......
  • influxdb报错:cache-max-memory-size exceeded
    转载请注明出处:influxdb报错日志: 该错误信息表示InfluxDB引擎超过了缓存最大内存大小。这意味着InfluxDB的缓存使用量超出了配置的限制。要解决此问题,可以采取以下步骤来定位和解决:检查配置文件:首先,请确保InfluxDB配置文件中没有设置错误。在配置文件......
  • Lock wait timeout exceeded; try restarting transaction临时解决办法
    错误日志Errorupdatingdatabase.Cause:com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException:Lockwaittimeoutexceeded;tryrestartingtransaction###Theerrormayinvolvecom.zhonghe.userim.dao.mysql.CrmRoleDao.updateById-Inline###SQL:UPDATE......
  • .net 关于在program中使用AddNewtonsoftJson之后,继承于System.Text.Json.Serializatio
    首先,先说遇见的问题与代码示例,在.net代码中注册了如下代码.AddNewtonsoftJson(option=>{//使用本地时区option.SerializerSettings.DateTimeZoneHandling=DateTimeZoneHandling.Local;......
  • C#中使用Newtonsoft.Charp实现Json对象序列化与反序列化
    场景C#中使用Newtonsoft.Json实现对Json字符串的解析:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/105795048上面讲的对JSON字符串进行解析,实际就是JSON对象的反序列化。在与第三方进行交互时常需要封装对象,存储各种属性消息,然后将对象序列化为json字符串并进......
  • Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connect
    报错 Maxretriesexceededwithurl:/(CausedbyNewConnectionError('<urllib3.connection.HTTPSConnectionobjectat0x000001A73833FD00>:Failedtoestablishanewconnection:[WinError10060]  pipuninstallrequestsurllib3  #先卸载pipinstallre......
  • newtonsoft.json
    https://www.newtonsoft.com/jsonProductproduct=newProduct();product.Name="Apple";product.Expiry=newDateTime(2008,12,28);product.Sizes=newstring[]{"Small"};stringjson=JsonConvert.SerializeObject(product);//{......
  • 关于Newtonsoft.Json的随笔
    在工作中一些陈旧项目,难免引用了一些很老版本,在一次升级中,项目引用的Newtonsoft.Json.dll突然少了一些method和class1,原来的:(咱也不懂为啥没有版本号嘞 2,升级后的 问题:1,原来使用的函数不存在,但是其实还在,换地方了而已,以下是修改:Newtonsoft.Json.JavaScriptConvert.Seria......
  • Newtonsoft.Json:JObject 动态添加字段/List<JObject>转DataTable
    1.JObject动态添加字段;varjsonObject=newJObject();foreach(varkeyinKeys){jsonObject.Add(key,value);}jsonObject.Add("*****","1");2. List<JObject>转DataTable1): 首先List<JObject>转stringList<JObject>jso......