none
working in vs 2010, and not in vs 2012 RRS feed

  • Question

  • unable to cast object of type 'system.invalidoperationexception' to type 'system.web.httpexception
    Thursday, March 6, 2014 12:16 PM

Answers

  • Your code is not designed to work in different situations. Try this:

    Exception e = Server.GetLastError();

    HttpException he = e as HttpException;

    If( he != null)

    {

        // process HttpException

        . . . .

    } else {

        // otherwise perform default processing of Exception, or try other casts.


    Thursday, March 6, 2014 1:02 PM

All replies

  • Intercept both of exceptions using two separate catch.

    Or show details of the source code here.

    Thursday, March 6, 2014 12:31 PM
  • i have two project one in vs 2010 and in vs 2102,

    in vs 2010, my code run properly, but in vs 2102 i got the error in catch block "unable to cast object of type 'system.invalidoperationexception' to type 'system.web.httpexception"

    Thursday, March 6, 2014 12:36 PM
  •  System.Exception appException = Server.GetLastError();
     HttpException checkException = (HttpException)appException;

    at second line i get exception.

    Thursday, March 6, 2014 12:44 PM
  • Your code is not designed to work in different situations. Try this:

    Exception e = Server.GetLastError();

    HttpException he = e as HttpException;

    If( he != null)

    {

        // process HttpException

        . . . .

    } else {

        // otherwise perform default processing of Exception, or try other casts.


    Thursday, March 6, 2014 1:02 PM