Object reference not set to an instance of an object

D

Daniel Groh

I have a user control with this code:

ASCX:
public string strTituloHTML
{
get{return objRmTituloPagina.GetString("CadastroUsuario.aspx");
}
---

I take this value in my ASPX

ASPX:
Cabecalho objTitulo = new Cabecalho(); <--user control instance
_titulo.InnerHtml = objTitulo.strTituloHTML;

THIS ABOVE WORK PERFECT!




BUT THIS BELLOW NOT, when i change in my user control for the correct form:

ASCX:
public string strTituloHTML
{
get{return objRmTituloPagina.GetString(System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])); <--Here the warning
}

I have the follow warning: Object reference not set to an instance of an object

I have a response.write(objRmTituloPagina.GetString(System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]));) in the Page_Load in my ASCX and no problem, this is happening just on my propety strTituloHTML.

Could someone help me ?
 
M

Morten Wennevik

Hi Daniel,

This isn't an answer to your question, but just an an advice.

Please use text only. If you do have to use html, keep it at a minimum. We are fully capable of reading your message without the screaming colors, bold and italic.
 
N

Nick Malik [Microsoft]

Hi Daniel,

You quote a line that does three different things. How in the world do you know, for certain, which one of those things are failing?

This line
get{return objRmTituloPagina.GetString(System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])); <--Here the warning

is the same as these lines
get {
string scriptname = Request.ServerVariables["SCRIPT_NAME"];
string filename = System.IO.Path.GetFileName(scriptname);
return objRmTituloPagina.GetString(filename);
}

The second is just as efficient. However, you get the advantage of seeing the error on the call where the error occurs. Each of the three lines above can fail (for different reasons). If you don't seperate out the lines, it becomes really difficult to tell which assignment, and which method call, is actually failing.

I don't know which is failing from looking at this snippet of code. However, I believe you can get your answer by breaking apart your line.
Perhaps, objRmTituloPagina is not being set correctly? Perhaps the filename doesn't exist?

--
--- 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.
--
I have a user control with this code:

ASCX:
public string strTituloHTML
{
get{return objRmTituloPagina.GetString("CadastroUsuario.aspx");
}
---

I take this value in my ASPX

ASPX:
Cabecalho objTitulo = new Cabecalho(); <--user control instance
_titulo.InnerHtml = objTitulo.strTituloHTML;

THIS ABOVE WORK PERFECT!




BUT THIS BELLOW NOT, when i change in my user control for the correct form:

ASCX:
public string strTituloHTML
{
get{return objRmTituloPagina.GetString(System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"])); <--Here the warning
}

I have the follow warning: Object reference not set to an instance of an object

I have a response.write(objRmTituloPagina.GetString(System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]));) in the Page_Load in my ASCX and no problem, this is happening just on my propety strTituloHTML.

Could someone help me ?
 

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

Top