Error on old code converted to VS 2005

B

Blasting Cap

I had some old code set to throw an email to me when a user hit an
exception.

VS 2003 worked fine with the code, VS 2005 when I run it in debug mode
pauses over the code each time, and gives me the message:

"HTTPException was unhandled by user code. Request Not Available in
this context."

This is the code that it says it doesn't like:

log2.WriteEntry("Remlink" & _
"MESSAGE: " & ex.Message.ToString & _
"\nURL: " & Request.Path & _
"\nSOURCE: " & ex.Source.ToString & _
"\nFORM: " & Request.Form.ToString() & _
"\nQUERYSTRING: " & Request.QueryString.ToString() & _
"\nTARGETSITE: " & ex.TargetSite.ToString & _
"\nSTACKTRACE: " & ex.StackTrace.ToString & _
EventLogEntryType.Error)

Basically, all I am doing is determining which log to write the event to
above, and then the code for the mail follows this code here.

Why is this thing now barfing on that particular line of code? Anything
I've found referencing the specific message has not been of any help.


Any ideas?
 
N

Nick Malik [Microsoft]

Your long concatentated string refers to the Request object twice:
"\nFORM: " & Request.Form.ToString() & _
"\nQUERYSTRING: " & Request.QueryString.ToString() & _

The change that you made appears to be more than just a recompile. This
code is part of a routine that you are now calling from a service or some
other code that is not running in ASP.Net context. Therefore, the Request
object is not available. If you are not in ASP.Net, then there is no form
or querystring, so these values are not valuable anyway. You may want to
refactor your routine to pass in the parameters you want, and then have the
calling code pass in either the asp.net bits when calling from a web page,
or pass in empty strings when calling from a non-asp.net context.


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 

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

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top