WebHandler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arjen

    WebHandler

    Hi,

    I get this wonderfull message when running my ashx file:
    Object reference not set to an instance of an object.

    I try to read data from the HttpContext. I think the problem is around
    here...
    I have allready add IRequiresSessio nState, but this did not help.

    Suggestion?

    Thanks!
    Arjen


  • Michael Nemtsev

    #2
    Re: WebHandler

    Hello Arjen,

    We are really not the clairvoyants to know what's wrong without seing your
    code. We need *worked* code to try to help u.

    You can find the problem by yourself. see where the problem in line the debugger
    screms, set the breakpoint and understand why that referenve was not initialized.

    AHi,
    AI get this wonderfull message when running my ashx file: Object
    Areference not set to an instance of an object.
    AI try to read data from the HttpContext. I think the problem is
    Aaround
    Ahere...
    AI have allready add IRequiresSessio nState, but this did not help.
    ASuggestion?

    ---
    WBR,
    Michael Nemtsev :: blog: http://spaces.live.com/laflour

    "At times one remains faithful to a cause only because its opponents do not
    cease to be insipid." (c) Friedrich Nietzsche


    Comment

    • Arjen

      #3
      Re: WebHandler

      Hmmm....

      // Inside my ashx file
      ArrayList data = GetData();

      // Inside cs file in app_code dir
      public static ArrayList GetData()
      {
      return (ArrayList)Http Context.Current .Items["MySettings "];
      }

      Data variable is null.

      I believe it have something to do with the processes that are currently
      loaded, or not yet loaded... but I don't see a solution.

      Arjen


      "Michael Nemtsev" <nemtsev@msn.co mschreef in bericht
      news:1799a79b3b c5ae8c8d1a2e356 364e@msnews.mic rosoft.com...
      Hello Arjen,
      >
      We are really not the clairvoyants to know what's wrong without seing your
      code. We need *worked* code to try to help u.
      >
      You can find the problem by yourself. see where the problem in line the
      debugger screms, set the breakpoint and understand why that referenve was
      not initialized.
      >
      AHi,
      AI get this wonderfull message when running my ashx file: Object
      Areference not set to an instance of an object.
      AI try to read data from the HttpContext. I think the problem is
      Aaround
      Ahere...
      AI have allready add IRequiresSessio nState, but this did not help.
      ASuggestion?
      >
      ---
      WBR,
      Michael Nemtsev :: blog: http://spaces.live.com/laflour
      >
      "At times one remains faithful to a cause only because its opponents do
      not cease to be insipid." (c) Friedrich Nietzsche
      >
      >

      Comment

      • Laurent Bugnion

        #4
        Re: WebHandler

        Hi,

        Arjen wrote:
        Hmmm....
        >
        // Inside my ashx file
        ArrayList data = GetData();
        >
        // Inside cs file in app_code dir
        public static ArrayList GetData()
        {
        return (ArrayList)Http Context.Current .Items["MySettings "];
        }
        >
        Data variable is null.
        >
        I believe it have something to do with the processes that are currently
        loaded, or not yet loaded... but I don't see a solution.
        >
        Arjen
        Difficult to know exactly what happens. The HttpContext.Cur rent is
        likely to exist in an ASHX instance.

        I would simply debug the server code. To do that, open the solution with
        the ASHX code inside, then select Debug / Attach to process, and select
        the ASP.NET process. Then add a breakpoint to the "GetData" line in the
        ASHX file. And then call the ASHX from your client. That should allow
        you to step in the code.

        HTH,
        Laurent
        --
        Laurent Bugnion, GalaSoft
        Software engineering: http://www.galasoft-LB.ch
        Private/Malaysia: http://mypage.bluewin.ch/lbugnion
        Support children in Calcutta: http://www.calcutta-espoir.ch

        Comment

        • Dave Sexton

          #5
          Re: WebHandler

          Hi Arjen,
          Data variable is null.
          Because HttpContext.Cur rent.Items["MySettings "] is returning null.

          Try modifying GetData to assign a default value (empty ArrayList perhaps) in
          the case that MySettings hasn't been assigned:

          public static ArrayList GetData()
          {
          ArrayList data = (ArrayList) HttpContext.Cur rent.Items["MySettings "];

          if (data = null)
          HttpContext.Cur rent.Items["MySettings "] = data = new ArrayList();

          return data;
          }

          --
          Dave Sexton

          "Arjen" <boah123@hotmai l.comwrote in message
          news:eitepv$bjn $1@news5.zwoll1 .ov.home.nl...
          Hmmm....
          >
          // Inside my ashx file
          ArrayList data = GetData();
          >
          // Inside cs file in app_code dir
          public static ArrayList GetData()
          {
          return (ArrayList)Http Context.Current .Items["MySettings "];
          }
          >
          Data variable is null.
          >
          I believe it have something to do with the processes that are currently
          loaded, or not yet loaded... but I don't see a solution.
          >
          Arjen
          >
          >
          "Michael Nemtsev" <nemtsev@msn.co mschreef in bericht
          news:1799a79b3b c5ae8c8d1a2e356 364e@msnews.mic rosoft.com...
          >Hello Arjen,
          >>
          >We are really not the clairvoyants to know what's wrong without seing your
          >code. We need *worked* code to try to help u.
          >>
          >You can find the problem by yourself. see where the problem in line the
          >debugger screms, set the breakpoint and understand why that referenve was
          >not initialized.
          >>
          >AHi,
          >AI get this wonderfull message when running my ashx file: Object
          >Areference not set to an instance of an object.
          >AI try to read data from the HttpContext. I think the problem is
          >Aaround
          >Ahere...
          >AI have allready add IRequiresSessio nState, but this did not help.
          >ASuggestion?
          >>
          >---
          >WBR,
          >Michael Nemtsev :: blog: http://spaces.live.com/laflour
          >>
          >"At times one remains faithful to a cause only because its opponents do not
          >cease to be insipid." (c) Friedrich Nietzsche
          >>
          >>
          >
          >

          Comment

          • Dave Sexton

            #6
            Re: WebHandler

            Hi Arjen,

            I just realized since this is a web app you'll want to synchronize that code:

            private static readonly object sync = new object();

            public static ArrayList GetData()
            {
            lock (sync)
            {
            ArrayList data = (ArrayList) HttpContext.Cur rent.Items["MySettings "];

            if (data = null)
            HttpContext.Cur rent.Items["MySettings "] = data = new ArrayList();

            return data;
            }
            }|

            --
            Dave Sexton

            "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
            news:%23MFJ%23s 3AHHA.4672@TK2M SFTNGP02.phx.gb l...
            Hi Arjen,
            >
            >Data variable is null.
            >
            Because HttpContext.Cur rent.Items["MySettings "] is returning null.
            >
            Try modifying GetData to assign a default value (empty ArrayList perhaps) in
            the case that MySettings hasn't been assigned:
            >
            public static ArrayList GetData()
            {
            ArrayList data = (ArrayList) HttpContext.Cur rent.Items["MySettings "];
            >
            if (data = null)
            HttpContext.Cur rent.Items["MySettings "] = data = new ArrayList();
            >
            return data;
            }
            >
            --
            Dave Sexton
            >
            "Arjen" <boah123@hotmai l.comwrote in message
            news:eitepv$bjn $1@news5.zwoll1 .ov.home.nl...
            >Hmmm....
            >>
            >// Inside my ashx file
            >ArrayList data = GetData();
            >>
            >// Inside cs file in app_code dir
            >public static ArrayList GetData()
            >{
            >return (ArrayList)Http Context.Current .Items["MySettings "];
            >}
            >>
            >Data variable is null.
            >>
            >I believe it have something to do with the processes that are currently
            >loaded, or not yet loaded... but I don't see a solution.
            >>
            >Arjen
            >>
            >>
            >"Michael Nemtsev" <nemtsev@msn.co mschreef in bericht
            >news:1799a79b3 bc5ae8c8d1a2e35 6364e@msnews.mi crosoft.com...
            >>Hello Arjen,
            >>>
            >>We are really not the clairvoyants to know what's wrong without seing your
            >>code. We need *worked* code to try to help u.
            >>>
            >>You can find the problem by yourself. see where the problem in line the
            >>debugger screms, set the breakpoint and understand why that referenve was
            >>not initialized.
            >>>
            >>AHi,
            >>AI get this wonderfull message when running my ashx file: Object
            >>Areference not set to an instance of an object.
            >>AI try to read data from the HttpContext. I think the problem is
            >>Aaround
            >>Ahere...
            >>AI have allready add IRequiresSessio nState, but this did not help.
            >>ASuggestion ?
            >>>
            >>---
            >>WBR,
            >>Michael Nemtsev :: blog: http://spaces.live.com/laflour
            >>>
            >>"At times one remains faithful to a cause only because its opponents do
            >>not cease to be insipid." (c) Friedrich Nietzsche
            >>>
            >>>
            >>
            >>
            >
            >

            Comment

            • Arjen

              #7
              Re: WebHandler

              Well, found the problem...

              I add items to the context in the Application_Pre RequestHandlerE xecute
              proces. And this proces is not loaded when browsing to an ashx file.

              Now I have to look for a work around.

              Thanks!


              "Dave Sexton" <dave@jwa[remove.this]online.comschre ef in bericht
              news:%23y5SC23A HHA.4024@TK2MSF TNGP04.phx.gbl. ..
              Hi Arjen,
              >
              I just realized since this is a web app you'll want to synchronize that
              code:
              >
              private static readonly object sync = new object();
              >
              public static ArrayList GetData()
              {
              lock (sync)
              {
              ArrayList data = (ArrayList)
              HttpContext.Cur rent.Items["MySettings "];
              >
              if (data = null)
              HttpContext.Cur rent.Items["MySettings "] = data = new
              ArrayList();
              >
              return data;
              }
              }|
              >
              --
              Dave Sexton
              >
              "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
              news:%23MFJ%23s 3AHHA.4672@TK2M SFTNGP02.phx.gb l...
              >Hi Arjen,
              >>
              >>Data variable is null.
              >>
              >Because HttpContext.Cur rent.Items["MySettings "] is returning null.
              >>
              >Try modifying GetData to assign a default value (empty ArrayList perhaps)
              >in the case that MySettings hasn't been assigned:
              >>
              >public static ArrayList GetData()
              >{
              > ArrayList data = (ArrayList) HttpContext.Cur rent.Items["MySettings "];
              >>
              > if (data = null)
              > HttpContext.Cur rent.Items["MySettings "] = data = new ArrayList();
              >>
              > return data;
              >}
              >>
              >--
              >Dave Sexton
              >>
              >"Arjen" <boah123@hotmai l.comwrote in message
              >news:eitepv$bj n$1@news5.zwoll 1.ov.home.nl...
              >>Hmmm....
              >>>
              >>// Inside my ashx file
              >>ArrayList data = GetData();
              >>>
              >>// Inside cs file in app_code dir
              >>public static ArrayList GetData()
              >>{
              >>return (ArrayList)Http Context.Current .Items["MySettings "];
              >>}
              >>>
              >>Data variable is null.
              >>>
              >>I believe it have something to do with the processes that are currently
              >>loaded, or not yet loaded... but I don't see a solution.
              >>>
              >>Arjen
              >>>
              >>>
              >>"Michael Nemtsev" <nemtsev@msn.co mschreef in bericht
              >>news:1799a79b 3bc5ae8c8d1a2e3 56364e@msnews.m icrosoft.com...
              >>>Hello Arjen,
              >>>>
              >>>We are really not the clairvoyants to know what's wrong without seing
              >>>your code. We need *worked* code to try to help u.
              >>>>
              >>>You can find the problem by yourself. see where the problem in line the
              >>>debugger screms, set the breakpoint and understand why that referenve
              >>>was not initialized.
              >>>>
              >>>AHi,
              >>>AI get this wonderfull message when running my ashx file: Object
              >>>Areference not set to an instance of an object.
              >>>AI try to read data from the HttpContext. I think the problem is
              >>>Aaround
              >>>Ahere...
              >>>AI have allready add IRequiresSessio nState, but this did not help.
              >>>ASuggestio n?
              >>>>
              >>>---
              >>>WBR,
              >>>Michael Nemtsev :: blog: http://spaces.live.com/laflour
              >>>>
              >>>"At times one remains faithful to a cause only because its opponents do
              >>>not cease to be insipid." (c) Friedrich Nietzsche
              >>>>
              >>>>
              >>>
              >>>
              >>
              >>
              >
              >

              Comment

              • Dave Sexton

                #8
                Re: WebHandler

                Hi Arjen,

                "ASP.NET Life Cycles"


                "ASP.NET Application Life Cycle Overview" might be of interest to you for this
                problem [link in reference above].

                --
                Dave Sexton

                "Arjen" <boah123@hotmai l.comwrote in message
                news:eitmtp$cb0 $1@news1.zwoll1 .ov.home.nl...
                Well, found the problem...
                >
                I add items to the context in the Application_Pre RequestHandlerE xecute
                proces. And this proces is not loaded when browsing to an ashx file.
                >
                Now I have to look for a work around.
                >
                Thanks!
                >
                >
                "Dave Sexton" <dave@jwa[remove.this]online.comschre ef in bericht
                news:%23y5SC23A HHA.4024@TK2MSF TNGP04.phx.gbl. ..
                >Hi Arjen,
                >>
                >I just realized since this is a web app you'll want to synchronize that
                >code:
                >>
                >private static readonly object sync = new object();
                >>
                >public static ArrayList GetData()
                >{
                > lock (sync)
                > {
                > ArrayList data = (ArrayList)
                >HttpContext.Cu rrent.Items["MySettings "];
                >>
                > if (data = null)
                > HttpContext.Cur rent.Items["MySettings "] = data = new
                >ArrayList();
                >>
                > return data;
                > }
                >}|
                >>
                >--
                >Dave Sexton
                >>
                >"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                >news:%23MFJ%23 s3AHHA.4672@TK2 MSFTNGP02.phx.g bl...
                >>Hi Arjen,
                >>>
                >>>Data variable is null.
                >>>
                >>Because HttpContext.Cur rent.Items["MySettings "] is returning null.
                >>>
                >>Try modifying GetData to assign a default value (empty ArrayList perhaps)
                >>in the case that MySettings hasn't been assigned:
                >>>
                >>public static ArrayList GetData()
                >>{
                >> ArrayList data = (ArrayList) HttpContext.Cur rent.Items["MySettings "];
                >>>
                >> if (data = null)
                >> HttpContext.Cur rent.Items["MySettings "] = data = new ArrayList();
                >>>
                >> return data;
                >>}
                >>>
                >>--
                >>Dave Sexton
                >>>
                >>"Arjen" <boah123@hotmai l.comwrote in message
                >>news:eitepv$b jn$1@news5.zwol l1.ov.home.nl.. .
                >>>Hmmm....
                >>>>
                >>>// Inside my ashx file
                >>>ArrayList data = GetData();
                >>>>
                >>>// Inside cs file in app_code dir
                >>>public static ArrayList GetData()
                >>>{
                >>>return (ArrayList)Http Context.Current .Items["MySettings "];
                >>>}
                >>>>
                >>>Data variable is null.
                >>>>
                >>>I believe it have something to do with the processes that are currently
                >>>loaded, or not yet loaded... but I don't see a solution.
                >>>>
                >>>Arjen
                >>>>
                >>>>
                >>>"Michael Nemtsev" <nemtsev@msn.co mschreef in bericht
                >>>news:1799a79 b3bc5ae8c8d1a2e 356364e@msnews. microsoft.com.. .
                >>>>Hello Arjen,
                >>>>>
                >>>>We are really not the clairvoyants to know what's wrong without seing
                >>>>your code. We need *worked* code to try to help u.
                >>>>>
                >>>>You can find the problem by yourself. see where the problem in line the
                >>>>debugger screms, set the breakpoint and understand why that referenve
                >>>>was not initialized.
                >>>>>
                >>>>AHi,
                >>>>AI get this wonderfull message when running my ashx file: Object
                >>>>Areferenc e not set to an instance of an object.
                >>>>AI try to read data from the HttpContext. I think the problem is
                >>>>Aaround
                >>>>Ahere...
                >>>>AI have allready add IRequiresSessio nState, but this did not help.
                >>>>ASuggestion ?
                >>>>>
                >>>>---
                >>>>WBR,
                >>>>Michael Nemtsev :: blog: http://spaces.live.com/laflour
                >>>>>
                >>>>"At times one remains faithful to a cause only because its opponents do
                >>>>not cease to be insipid." (c) Friedrich Nietzsche
                >>>>>
                >>>>>
                >>>>
                >>>>
                >>>
                >>>
                >>
                >>
                >
                >

                Comment

                Working...