C# – Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

c

if (!advertismentsDao.AdvertisementUrlExist(ad.Url))
{
    if (!advertismentsDao.AdvertisementExist(ad.Price, 
                                             ad.HollidayDuration, 
                                             ad.Name, 
                                             ad.Description, 
                                             ad.City, 
                                             ad.Area, 
                                             ad.Country,
                                             ad.Agency))
    {
       advertismentsDao.Save(ad);
       advertismentsDao.CommitChanges(); 
    }
}

gives me:

InnerException = Unable to evaluate
expression because the code is
optimized or a native frame is on top
of the call stack.

error is wheren i got here CommitChanges(). I google but i can not solve my problem

Best Answer

I suspect that's not actually the inner exception - I suspect that's just what the debugger's showing you when you try to inspect the exception.

Dump a complete stack trace to a log instead, and that should give the real exception, which should then make it clear why the commit failed.