Orchard 事件通知小坑

public void GetTagLogRecord(int tagId, string keyword, string area) {
            var tag = _repositoryTagRecord.Get(tagId);
            OnlineGet(tag, keyword, area);
        }

  

_jobsQueueService.Enqueue("IClawerService.GetTagLogRecord", new Dictionary<string, object> {
                                { "tagId", tag.Id }
                                , { "keyword", tag.Keyword }
                                , { "area", area }
                            }, 1);
if (cachedDelegate != null) {
                var args = cachedDelegate.Item1.Select(methodParameter => arguments[methodParameter.Name]).ToArray();
    //此处args为object[]数组,调用下面的一句话始终报转换无效的错误,
//调试时将args手动构造成 args = new object[] { 23, "PPAPI", "" };又没问题 !!!!!!
//不知道是不是.NET的bug !!!
                var result = cachedDelegate.Item2(eventHandler, args);

                returnValue = result as IEnumerable;
                if (result != null && (returnValue == null || result is string))
                    returnValue = new[] { result };
                return true;
            }    

  

否则  cachedDelegate.Item2  始终报错 :  指定的转换无效 !!!!!

2015.10.14最新进展

根本原因分析,入参字典   tagId 传入 int类型 9

在orchard反解析的过程中  会将数值类型转换为 long

private static object Convert(this JToken jToken) {
            if (jToken == null) {
                throw new ArgumentNullException();
            }

            switch (jToken.Type) {
                case JTokenType.Array:
                    var array = jToken as JArray;
                    return array.Values().Select(Convert).ToArray();
                case JTokenType.Object:
                    var obj = jToken as JObject;
                    return obj
                        .Properties()
                        .ToDictionary(property => property.Name, property => Convert(property.Value));
                default:
//这里会将9 转换为long类型
                    return jToken.ToObject<object>();
            }
        }

  解决办法 :   入参字典统一传没有类型歧义的  string !!!!!!

原文地址:https://www.cnblogs.com/cabbage/p/4876318.html