“/”应用程序中的服务器错误。未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 37: 
行 38:                      //Get enumerator
行 39:                      IEnumerator<KeyValuePair<string, ADReport>>  CacheEnum = Items.GetEnumerator();
行 40:                      //Items.GetEnumerator();
行 41:                      //loop

解决方案 »

  1.   

    Items.GetEnumerator();取出来是空的
      

  2.   

    很有可能是你的Items这个变量没有初始化实例,能提供你上下文更多源代码信息看看吗?
      

  3.   


    是什么问题,使得Items.GetEnumerator();取出来是空的呢?
      

  4.   

       private int NCPM;
            private int NCPM_C;
        
             private void Page_Load(object sender, System.EventArgs e)
                     {
                         hlRefresh.NavigateUrl = Request.RawUrl;
                         //In a cluster, it might be nice to know which machine we are on.
                         litMachine.Text = System.Environment.MachineName;                     //Bind CachedItems
                         BindGrid();
                     }
        
       
                     //Bind the grid with items found in the cache.
                     private void BindGrid()
                     {
                         //Create an arraylist to hold our cacheditem details
                         ArrayList al = new ArrayList(); string KEY = "ADREPORT_LIST";
                IDictionary<string, ADReport> Items = (IDictionary<string, ADReport>)HttpContext.Current.
                    Cache.Get(KEY);                     //Get enumerator
                         IEnumerator<KeyValuePair<string, ADReport>>  CacheEnum = Items.GetEnumerator();
                         //Items.GetEnumerator();
                         //loop
                         while (CacheEnum.MoveNext())
                         {
                             try
                             {
                                 //Do we want to include this item
                                 if(IncludeInList(CacheEnum.Current.Key.ToString()))
                                 {
     IList il = CacheEnum.Current.Value as IList;
     ADReport dic = CacheEnum.Current.Value as ADReport;
     if(il != null || dic != null)
     {
    al.Add(new CachedItem(CacheEnum.Current.Key.ToString(),CacheEnum.Current.Value.CPM, CacheEnum.Current.Value.CPM_C));
    NCPM += CacheEnum.Current.Value.CPM;
    NCPM_C += CacheEnum.Current.Value.CPM_C;
      }
                                 }
                             }
                             catch{}
                         }
                         //set counter Literal
                         litCount.Text = NCPM.ToString();      litCount_C.Text = NCPM_C.ToString();
        
                         //Bind
                         //dgCachedItems.DataSource = al;
                         //dgCachedItems.DataBind();
        
                     }
      

  5.   

    你的HttpContext.Current.Cache.Get(KEY)
    取出来是个null吧!?再往上查找一下原因?