日期:2014-05-18  浏览次数:21400 次

急急急!无法将类型为“System.Object[]”的对象强制转换为类型“System.IConvertible”顶也给分!
C# code
    



  public void AsyncRefreshLogisticsCompany(int shopId)
        {
            IsBusy = true;
            ThreadPool.QueueUserWorkItem(RefreshLogisticsCompany,new object[]{shopId});
        }

        /// <summary>
        /// 获取物流公司
        /// </summary>
        /// <param name="state"></param>
        private void RefreshLogisticsCompany(object state)
        {
            var result = new SunyuResult();
            try
            {
               [color=#FF0000] var shopId = Convert.ToInt32(state);----------在这里抛出的异常[/color]                var shop = ShopDB.GetShopById(shopId);

时间 2012/8/21 10:09:31 捕获异常 System.InvalidCastException: 无法将类型为“System.Object[]”的对象强制转换为类型“System.IConvertible”。
   在 System.Convert.ToInt32(Object value)



------解决方案--------------------
传入的是数组,因此

object[] paras = (object[])state;
var shopId = Convert.ToInt32(paras[0]);
------解决方案--------------------
state是什么???

Convert.ToInt32(state.tostring());看看
------解决方案--------------------
或者直接传入int不行吗?
 public void AsyncRefreshLogisticsCompany(int shopId)
{
IsBusy = true;
ThreadPool.QueueUserWorkItem(RefreshLogisticsCompany,shopId);
}


 private void RefreshLogisticsCompany(object state)
{
var result = new SunyuResult();
try
{
var shopId = Convert.ToInt32(state)