堆栈跟踪中的递归调用但代码 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 调用的私有方法,你 do 调用它。

启用优化后,堆栈跟踪并不总是 100% 准确。特别是当调用微不足道的方法时,这些方法几乎肯定会被内联。 Dictionary<,>.Add 是一个非常简单的方法:它除了调用 Dictionary<,>.Insert 之外什么都不做。似乎已恢复足够的信息来确定 Dictionary<,>.InsertGetConfigFromDB 之间存在 某物 ,但不确定该物可能是什么。因为没有更好的可用,名称 GetConfigFromDB 被第二次使用。