使用dynamic引发的异常:无法对 null 引用执行运行时绑定

今天上午运营反映有商户的账单没有生成。

查看日志,在批量生成账单服务执行过程中,因为如下异常而中断了:

跑批异常 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 无法对 null 引用执行运行时绑定
   在 CallSite.Target(Closure , CallSite , Object )
   在 System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   在 GateWay.BLL.Orders.PayFilesGenerator.Generate()
 2       {
 3           //查找distinct后的“商户&日期”
 4           var map = orderDal.GetMerchantsForSettlement(_frDate, _toDate);
 5           if (map == null)
 6           {
 7               _logHelper.WriteLog("no records");
 8               return;
 9           }
10           _logHelper.WriteLog("获取到{0}条“商户&日期”对儿", map.Count);
11           int i = 0;
12           //遍历“商户&日期”集合,逐一查询出来订单然后生成文件
13           foreach (var p in map)
14           {
15               i++;
16               _logHelper.WriteLog("[{2}] 商户:{0}-文件日期:{1}", p.MerCode, p.Date.ToShortDateString(), i);
17               try
18               {
19                   var isOK = Generate(p.MerCode, p.Date);
20                   _logHelper.WriteLog("[{0}]生成文件返回{1}", i, isOK);
21               }
22               catch (Exception ex)
23               {
24                   if (ex is ResponseErrorException)
25                   {
26                       _logHelper.WriteLog("[{0}]{1}", i, ex.Message);
27                   }
28                   else
29                   {
30                       _logHelper.WriteLog("[{0}]文件生成异常 {1}", i, ex.ToString());
31                   }
32               }
33           }
34       }
35       catch (Exception ex)
36       {
37           _logHelper.WriteLog("跑批异常 {0}", ex.ToString());
38       }
40       _logHelper.WriteLog("本次批量生成账单文件结束.");
41   }