-1

虽然返回值不为空,但我在

var currentTakipciler = TwitterCacheDepo.GetTakipciler(TemaUserID)

我在调试中查看了返回值,它不是空的,但我得到了空引用异常。

try
{
    var currentTakipciler = TwitterCacheDepo.GetTakipciler(TemaUserID);
}
catch (Exception ex)
{
    Utils.LogYaz(ex.ToString());
}

public class TwitterCacheDepo
{
    ...
    ...

    public static Dictionary<int, string> GetTakipciler(string TemaUserID)
    {
        try
        {
            Dictionary<int, string> returnValue = new Dictionary<int, string>();
            if (allTakipciler != null && allTakipciler.Rows.Count > 0)
            {
                returnValue = allTakipciler.AsEnumerable().Where(x => x.Field<DateTime?>("BitTarih").Equals(null) && x.Field<string>("TemaUserID").Equals(TemaUserID)).ToDictionary(x => x.Field<int>("ID"), y => y.Field<string>("UserID"));// SqlDataBase.SqlGetTable("SELECT ID,TemaUserID,UserID,BitTarih FROM TBL_TwitterUserTakipciler WHERE BitTarih IS NULL SID = " + 4663);
                return returnValue;
            }
            else
            {
                allTakipciler = SqlDataBase.SqlGetTable("SELECT ID,TemaUserID,UserID,BitTarih FROM TBL_TwitterUserTakipciler WHERE SID = " + 4663);
                return allTakipciler.AsEnumerable().Where(x => x.Field<DateTime?>("BitTarih").Equals(null) && x.Field<string>("TemaUserID").Equals(TemaUserID)).ToDictionary(x => x.Field<int>("ID"), y => y.Field<string>("UserID"));
            }
        }
        catch (Exception ex)
        {
            Utils.LogYaz(ex.Message.ToString());
            return null;
        }
    }
}
4

1 回答 1

2

您需要查看完整的堆栈跟踪并检查引发 null ref 异常的确切行号。这将使您清楚地表明发生了什么。

要在不使用调试器的情况下运行堆栈跟踪,因为正如您所说,使用调试器无法重现问题。

于 2013-09-16T09:31:09.997 回答