簡體   English   中英

堆棧跟蹤中的遞歸調用,但代碼C#中沒有

[英]recursive call in stack trace but nothing in code C#

我最近在C#.Net應用程序中遇到了一個問題。 未修改的堆棧跟蹤如下所示:

2018-09-12 21:08:31,596 [] [112] ERROR PLoggerFactory::RunLogic - Exception : System.Exception: Serialisation errorSystem.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Block`2.GetConfigFromDB()
   at Block`2.GetConfigFromDB()
   at Block`2.Begin(IParcelGettable`1 P, Action`1 f)
   at Run.<>c__DisplayClass45_0.<RunInNewThread>b__1()

在上面,在堆棧中調用GetConfigFromDB 但是我已經驗證了代碼,其中沒有遞歸的GetConfigFromDB。 這可能嗎?

請讓我知道是否需要GetConfigFromDB的代碼,我將對其進行修改並共享。

-----編輯-------添加了代碼

private Dictionary<string, object> GetConfigFromDB()
        {

            blockConfigJson = controller.BlockConfig.GetConfig(this.BlockInstanceId);
            if (String.IsNullOrEmpty(blockConfigJson))
            {
                return new Dictionary<string, object>();
            }
            Dictionary<string, object> configDictionary = new Dictionary<string, object>();
            try
            {
                configDictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(blockConfigJson);
                foreach (var v in configDictionary)
                {
                    var key = "__" + this.BlockInstanceId + "." + v.Key;
                    if (SharedConfig.ContainsKey(key))
                    {
                        SharedConfig[key] = v.Value;
                    }
                    else
                    {
                        SharedConfig.Add(key, v.Value);
                    }

                    if (v.Key.Trim() == "_extraInfo_")
                    {
                        dynamic extraInfo = JsonConvert.DeserializeObject(configDictionary["_extraInfo_"].ToString());
                        JsonConvert.DeserializeObject<List<Variable>>(extraInfo["Variables"].ToString());
                        Dictionary<string, string> _variablesTemp = new Dictionary<string, string>();
                        try
                        {
                            _variablesTemp = JsonConvert.DeserializeObject<Dictionary<string, string>>(extraInfo["Variables"].ToString());
                        }
                        catch (Exception ex)
                        {
                            mLogger.Debug("Variable parsing error " + ex);
                        }


                        List<Variable> _variables = new List<Variable>();
                        foreach (KeyValuePair<string, string> kyp in _variablesTemp)
                        {
                            _variables.Add(new Variable()
                            {
                                variableName = kyp.Key,
                                variableValue = kyp.Value
                            });
                        }

                        foreach (Variable _variable in _variables)
                        {
                            if (!SharedVariables.ContainsKey(_variable.variableName))
                            {
                                SharedVariables.Add(_variable.variableName, _variable.variableValue);
                                new Caching().Send(_variable.variableName, _EvaluateConfigValue(_variable.variableValue, this.blockConfig, this.SharedConfig, this.SharedVariables, this.propagatedConfig, this.propagatedVariables, this.ControlId));
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {

                configDictionary = new Dictionary<string, object>();
                throw;
            }
            return configDictionary;
        }

該堆棧跟蹤顯示了調用Dictionary<,>.Insert(TKey, TValue, bool) ,但是您當然從不這樣做。 您不能,因為那是由Dictionary<,>.Add調用的私有方法,您確實要調用它。

啟用優化后,堆棧跟蹤不一定總是100%准確。 尤其是在調用瑣碎的方法時,幾乎肯定會內聯。 Dictionary<,>.Add是一個簡單的方法:從字面上看,除了調用Dictionary<,>.Insert別無其他。 似乎已恢復了足夠的信息,以確定在Dictionary<,>.InsertGetConfigFromDB之間是否存在某些東西 ,但可能不是什么。 因為沒有更好的選擇,所以第二次使用名稱GetConfigFromDB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM