NullReferenceException in Profile

S

Saber

in <system.web> of web.config I've:
[...]
<profile>
<properties>
<add name="EnterTime" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>

And in Session_Start of global.asax:
[...]
Profile.EnterTime = System.DateTime.Now '**** Line 26

But I get an error message in line 26:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
 
S

Saber

Thanks Eliyahu,
I used your syntax:
Dim EnterTime As String = System.DateTime.Now.ToString
HttpContext.Current.Profile.GetPropertyValue(EnterTime)

but again the same error, here is the error details:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_global.asax.5_wxyugz"
StackTrace:
at ASP.global_asax.Session_Start(Object sender, EventArgs e) in
C:\Documents and Settings\saber\My Documents\Visual Studio
2005\WebSites\WebTesting\global.asax:line 27
at System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs
e)
at System.Web.SessionState.SessionStateModule.OnStart(EventArgs e)
at System.Web.SessionState.SessionStateModule.CompleteAcquireState()
at
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source,
EventArgs e, AsyncCallback cb, Object extraData)
at
System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

Eliyahu Goldin said:
The syntax you are using is good for an aspx file for a page. In
global.asax Profile is not defined . You can access it via
HttpContext.Current with syntax:

HttpContext.Current.Profile.GetPropertyValue("EnterTime");

Eliyahu

Saber said:
in <system.web> of web.config I've:
[...]
<profile>
<properties>
<add name="EnterTime" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>

And in Session_Start of global.asax:
[...]
Profile.EnterTime = System.DateTime.Now '**** Line 26

But I get an error message in line 26:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
 
S

Saber

There is no difference in C# and VB syntax in this case (except the
semicolon of end of line!),
Thank you for showing me the right way, I've to use *SetPropertyValue*
because I'm writing
a value not reading.

VB:
Dim EnterTime As String = System.DateTime.Now.ToString
HttpContext.Current.Profile.SetPropertyValue("EnterTime", EnterTime)

C#:
string EnterTime = System.DateTime.Now.ToString();
HttpContext.Current.Profile.SetPropertyValue("EnterTime", EnterTime);

BUT again the same error message(NullReferenceException) :(


Eliyahu Goldin said:
I am not good in VB.

In GetPropertyValue(EnterTime) EnterTime should a string constant. In c# I
would write GetPropertyValue("EnterTime").

Eliyahu

Saber said:
Thanks Eliyahu,
I used your syntax:
Dim EnterTime As String = System.DateTime.Now.ToString
HttpContext.Current.Profile.GetPropertyValue(EnterTime)

but again the same error, here is the error details:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_global.asax.5_wxyugz"
StackTrace:
at ASP.global_asax.Session_Start(Object sender, EventArgs e) in
C:\Documents and Settings\saber\My Documents\Visual Studio
2005\WebSites\WebTesting\global.asax:line 27
at
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e)
at System.Web.SessionState.SessionStateModule.OnStart(EventArgs e)
at
System.Web.SessionState.SessionStateModule.CompleteAcquireState()
at
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object
source, EventArgs e, AsyncCallback cb, Object extraData)
at
System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

Eliyahu Goldin said:
The syntax you are using is good for an aspx file for a page. In
global.asax Profile is not defined . You can access it via
HttpContext.Current with syntax:

HttpContext.Current.Profile.GetPropertyValue("EnterTime");

Eliyahu

"Saber" <saber[.AT.]oxin.ir> wrote in message
in <system.web> of web.config I've:
[...]
<profile>
<properties>
<add name="EnterTime" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>

And in Session_Start of global.asax:
[...]
Profile.EnterTime = System.DateTime.Now '**** Line 26

But I get an error message in line 26:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
 
E

Eliyahu Goldin

The syntax you are using is good for an aspx file for a page. In global.asax
Profile is not defined . You can access it via HttpContext.Current with
syntax:

HttpContext.Current.Profile.GetPropertyValue("EnterTime");

Eliyahu
 
E

Eliyahu Goldin

I am not good in VB.

In GetPropertyValue(EnterTime) EnterTime should a string constant. In c# I
would write GetPropertyValue("EnterTime").

Eliyahu

Saber said:
Thanks Eliyahu,
I used your syntax:
Dim EnterTime As String = System.DateTime.Now.ToString
HttpContext.Current.Profile.GetPropertyValue(EnterTime)

but again the same error, here is the error details:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_global.asax.5_wxyugz"
StackTrace:
at ASP.global_asax.Session_Start(Object sender, EventArgs e) in
C:\Documents and Settings\saber\My Documents\Visual Studio
2005\WebSites\WebTesting\global.asax:line 27
at System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs
e)
at System.Web.SessionState.SessionStateModule.OnStart(EventArgs e)
at System.Web.SessionState.SessionStateModule.CompleteAcquireState()
at
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object
source, EventArgs e, AsyncCallback cb, Object extraData)
at
System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

Eliyahu Goldin said:
The syntax you are using is good for an aspx file for a page. In
global.asax Profile is not defined . You can access it via
HttpContext.Current with syntax:

HttpContext.Current.Profile.GetPropertyValue("EnterTime");

Eliyahu

Saber said:
in <system.web> of web.config I've:
[...]
<profile>
<properties>
<add name="EnterTime" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>

And in Session_Start of global.asax:
[...]
Profile.EnterTime = System.DateTime.Now '**** Line 26

But I get an error message in line 26:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
 
S

Saber

What can make a NullReferenceException when trying to read/write a Profile
value?
I configured the database using aspnet_regsql.exe wizard.
How to test it configured properly?
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top