//always works, returning a valid object into _page _page = _httpContext.Handler as System.Web.UI.Page; //Fails throwing the exception : Unable to cast object of type 'System.Web.DefaultHttpHandler' to type 'System.Web.UI.Page' _page = (System.Web.UI.Page)_httpContext.Handler;
I would like to know why this is happening?
EDIT:
//Fixes the problem if(_httpContext.Handler is System.Web.UI.Page) _page = (System.Web.UI.Page)_httpContext.Handler;
If I debug the keyword expression "how", I never get a null reference (the object is always assigned properly). However, () cast throws an exception if it does not have an if status.
EDIT: After about 15 runs through the class, I was able to get zero. It looks like it took more runs to find zero compared to how quickly the cast () throws an exception.
OLD: when debugging in the "how" statement every time a class launches breakpoint hits, it never matters.
If tt has debugging in the expression '() within the if range, every time a breakpoint falls into the cast, it works correctly. Werid
Mausimo
source share