Problem with Class name

T

tshad

I am getting the following messages from my compile code:

PageInit.cs(43,71): error CS0246: The type or namespace name 'User' could
not be
found (are you missing a using directive or an assembly reference?)
PageInit.cs(43,76): error CS0117: 'object' does not contain a definition for
'LastPageVisited'

User is an object I have in my session variables that works fine in VB.Net
but there is something missing here.

The Compiler Code is:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library PageInit.cs
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll /r:User.dll

The code snippet giving me the problem looks like (the last line is the
offender):
************************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Microsoft.VisualBasic;
using MyFunctions;

namespace MyFunctions
{
public class PageInit
{
public static void PageSetup(MyFunctions.Page thePage)
{
HttpContext.Current.Session["LastPageVisited"] =
(User)HttpContext.Current.Session["User"].LastPageVisited;
***********************************

My User class looks something like:
********************************
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using MyFunctions;
using FtsData;

namespace RolesBasedAuthentication
{
[Serializable]
public class User
{
private string lastPageVisited = "";
....
public string LastPageVisited
{
get { return lastPageVisited; }
set { lastPageVisited = value; }
}
....
*************************************

This is the piece that is giving me the problem:

(User)HttpContext.Current.Session["User"].LastPageVisited

Why doesn't it see the User object? It is in the MyFunctions namespace. I
also tried adding the following line just to see:

using Myfunctions;

But that didn't work, either.

Thanks,

Tom
 
T

tshad

Sorry, this is resend of my previous message.

I got an error that said the old one didn't get sent and it obviously did.

Tom
 
C

Cor Ligthert[MVP]

Tshad,

The chance that User is abigious in one of the other namespaces that you
have declared as using is high. Did you try it with writting the full path
to that. (Because of this it is not so clever to call a class User by the
way, however, it is not so bad as trying to name a class "string").

Cor
 
T

tshad

The problem here was that I didn't have a "using RolesBasedAuthentication;"
line. I thought it was in the "MyFunction" namespace.

I am still getting this error, even if I change:

HttpContext.Current.Session["LastPageVisited"] =
(User)HttpContext.Current.Session["User"].LastPageVisited;

to

HttpContext.Current.Session["LastPageVisited"] =
(User)(HttpContext.Current.Session["User"]).LastPageVisited;

or

HttpContext.Current.Session["LastPageVisited"] =
(RolesBasedAuthentication.User)(HttpContext.Current.Session["User"]).LastPageVisited;

But the Class User does have a LastPageVisited:

public string LastPageVisited
{
get { return lastPageVisited; }
set { lastPageVisited = value; }
}

Am I casting it wrong??

Thanks,

Tom
User is an object I have in my session variables that works fine in
VB.Net but there is something missing here.

The Compiler Code is:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library PageInit.cs
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll /r:User.dll

The code snippet giving me the problem looks like (the last line is the
offender):
************************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Microsoft.VisualBasic;
using MyFunctions;

namespace MyFunctions
{
public class PageInit
{
public static void PageSetup(MyFunctions.Page thePage)
{
HttpContext.Current.Session["LastPageVisited"] =
(User)HttpContext.Current.Session["User"].LastPageVisited;
***********************************

My User class looks something like:
********************************
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using MyFunctions;
using FtsData;

namespace RolesBasedAuthentication
{
[Serializable]
public class User
{
private string lastPageVisited = "";
...
public string LastPageVisited
{
get { return lastPageVisited; }
set { lastPageVisited = value; }
}
...
*************************************

This is the piece that is giving me the problem:

(User)HttpContext.Current.Session["User"].LastPageVisited

Why doesn't it see the User object? It is in the MyFunctions namespace.
I also tried adding the following line just to see:

using Myfunctions;

But that didn't work, either.

Thanks,

Tom
 
T

tshad

Cor Ligthert said:
Tshad,

The chance that User is abigious in one of the other namespaces that you
have declared as using is high. Did you try it with writting the full path
to that. (Because of this it is not so clever to call a class User by the
way, however, it is not so bad as trying to name a class "string").

I tried that but that wasn't the problem.

Part of it was that I thought the namespace was "MyFunctions" but it wasn't.
It was RolesBasedAuthentication. When I added:

using RolesBasedAuthentication;

That fixed the first problem.

Thanks,

Tom
 
J

Jon Skeet [C# MVP]

HttpContext.Current.Session["LastPageVisited"] =
(User)(HttpContext.Current.Session["User"]).LastPageVisited;

That's trying to cast the result of LastPageVisited to User. Change it
to:

HttpContext.Current.Session["LastPageVisited"] =
((User)HttpContext.Current.Session["User"]).LastPageVisited;

Jon
 
T

tshad

Jon Skeet said:
HttpContext.Current.Session["LastPageVisited"] =
(User)(HttpContext.Current.Session["User"]).LastPageVisited;

That's trying to cast the result of LastPageVisited to User. Change it
to:

HttpContext.Current.Session["LastPageVisited"] =
((User)HttpContext.Current.Session["User"]).LastPageVisited;

That was it.

Took me a little while to see why. I was thinking that I was looking only
at HttpContext.Current.Session["User"]) by doing it my way, but I can see
now why that is not the case.

Thanks,

Tom
 

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