WebHandler

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

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 IRequiresSessionState, but this did not help.

Suggestion?

Thanks!
Arjen
 
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.

A> Hi,
A> I get this wonderfull message when running my ashx file: Object
A> reference not set to an instance of an object.
A> I try to read data from the HttpContext. I think the problem is
A> around
A> here...
A> I have allready add IRequiresSessionState, but this did not help.
A> Suggestion?

---
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 Nietzsch
 
Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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
 
Hi,
Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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.Current 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
 
Hi Arjen,
Data variable is null.

Because HttpContext.Current.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.Current.Items["MySettings"];

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

return data;
}

--
Dave Sexton

Arjen said:
Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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 said:
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.

A> Hi,
A> I get this wonderfull message when running my ashx file: Object
A> reference not set to an instance of an object.
A> I try to read data from the HttpContext. I think the problem is
A> around
A> here...
A> I have allready add IRequiresSessionState, but this did not help.
A> Suggestion?

---
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
 
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.Current.Items["MySettings"];

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

return data;
}
}|

--
Dave Sexton

Dave Sexton said:
Hi Arjen,
Data variable is null.

Because HttpContext.Current.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.Current.Items["MySettings"];

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

return data;
}

--
Dave Sexton

Arjen said:
Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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 said:
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.

A> Hi,
A> I get this wonderfull message when running my ashx file: Object
A> reference not set to an instance of an object.
A> I try to read data from the HttpContext. I think the problem is
A> around
A> here...
A> I have allready add IRequiresSessionState, but this did not help.
A> Suggestion?

---
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
 
Well, found the problem...

I add items to the context in the Application_PreRequestHandlerExecute
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 said:
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.Current.Items["MySettings"];

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

return data;
}
}|

--
Dave Sexton

Dave Sexton said:
Hi Arjen,
Data variable is null.

Because HttpContext.Current.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.Current.Items["MySettings"];

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

return data;
}

--
Dave Sexton

Arjen said:
Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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" <[email protected]> schreef in bericht
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.

A> Hi,
A> I get this wonderfull message when running my ashx file: Object
A> reference not set to an instance of an object.
A> I try to read data from the HttpContext. I think the problem is
A> around
A> here...
A> I have allready add IRequiresSessionState, but this did not help.
A> Suggestion?

---
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
 
Hi Arjen,

"ASP.NET Life Cycles"
http://msdn2.microsoft.com/en-us/library/ms227435.aspx

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

--
Dave Sexton

Arjen said:
Well, found the problem...

I add items to the context in the Application_PreRequestHandlerExecute
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 said:
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.Current.Items["MySettings"];

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

return data;
}
}|

--
Dave Sexton

Dave Sexton said:
Hi Arjen,

Data variable is null.

Because HttpContext.Current.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.Current.Items["MySettings"];

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

return data;
}

--
Dave Sexton

Hmmm....

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

// Inside cs file in app_code dir
public static ArrayList GetData()
{
return (ArrayList)HttpContext.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" <[email protected]> schreef in bericht
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.

A> Hi,
A> I get this wonderfull message when running my ashx file: Object
A> reference not set to an instance of an object.
A> I try to read data from the HttpContext. I think the problem is
A> around
A> here...
A> I have allready add IRequiresSessionState, but this did not help.
A> Suggestion?

---
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top