Invalid Cast Exception on Context.ApplicationInstance

Discussion in 'ASP .Net' started by Mark Olbert, Dec 4, 2003.

  1. Mark Olbert

    Mark Olbert Guest

    I have a v1.1 webapp that works fine on two different servers (my development machine and a
    Verio-hosted site). However, it blows up on a MaximumASP-hosted site at a particular line:

    private void Page_Load(object sender, System.EventArgs e)
    {
    // snippet
    theGlobal = (Global) Context.ApplicationInstance;
    }

    I put a bunch of site-wide methods and properties in the Global.asax file and reference them through
    this cast.

    Does anyone have any idea why this would work in some environments and not others?

    Thanx in advance for any help or advice.

    - Mark
     
    Mark Olbert, Dec 4, 2003
    #1
    1. Advertisements

  2. Hi Mark,

    Thank you for posting to the MSDN newsgroups.

    Please use "((global_asax)Context.ApplicationInstance)" and test this issue
    again.

    I hope it helps.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ┬ĘC www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jacob Yang [MSFT], Dec 5, 2003
    #2
    1. Advertisements

  3. Mark Olbert

    Mark Olbert Guest

    Jacob,

    Actually, the answer was even simpler: I'd forgotten to upload the global.asax file after I'd
    customized it's code-behind. The cast was failing because, without global.asax,
    Context.ApplicationInstance is an HttpApplication, but with global.asax present it's a Global.

    - Mark
     
    Mark Olbert, Dec 5, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.