By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Profile. What am I doing wrong?

P: n/a
Hello,

I am using a custom Profile provider as follows:

public class Profile : ProfileBase {

[SettingsAllowAnonymous(false)]
public Bio Bio { get; set; }

[SettingsAllowAnonymous(true)]
public Visitor Visitor { get; set; }

public static Profile Get() {
return Create(Membership.GetUser().UserName) as Profile;
}
public static Profile Get(string username) {
return Create(username) as Profile;
}

}

Visitor is a class has follows:

[Serializable()]
public class Visitor {
public CultureInfo Culture { get; set; }
}

On my web page I am overriding InitializeCulture, by getting the value
of Visitor.Culture:

1 protected override void InitializeCulture() {
2 base.InitializeCulture();
3 CultureInfo culture = Profile.Get().Visitor.Culture;
4 if (culture != null) {
5 Thread.CurrentThread.CurrentCulture = culture;
6 Thread.CurrentThread.CurrentUICulture = culture;
7 }
8 }

Because of code line 3 I always get an error on my profile provider:

1 public static Profile Get() {
2 return Create(Membership.GetUser().UserName) as Profile;
3 }

The error is on line 2 and says:

"Object reference not set to an instance of an object. Use the new
keyword to create an object instance."

What am I doing wrong?

Thanks,

Miguel
Oct 9 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Oct 9, 10:32*pm, shapper <mdmo...@gmail.comwrote:
Hello,

I am using a custom Profile provider as follows:

* public class Profile : ProfileBase {

* * [SettingsAllowAnonymous(false)]
* * public Bio Bio { get; set; }

* * [SettingsAllowAnonymous(true)]
* * public Visitor Visitor { get; set; }

* * public static Profile Get() {
* * * return Create(Membership.GetUser().UserName) as Profile;
* * }
* * public static Profile Get(string username) {
* * * return Create(username) as Profile;
* * }

* }

Visitor is a class has follows:

* [Serializable()]
* public class Visitor {
* * public CultureInfo Culture { get; set; }
* }

On my web page I am overriding InitializeCulture, by getting the value
of Visitor.Culture:

1 * * * *protected override void InitializeCulture() {
2 * * * * *base.InitializeCulture();
3 * * * * *CultureInfo culture = Profile.Get().Visitor.Culture;
4 * * * * *if (culture != null) {
5 * * * * * *Thread.CurrentThread.CurrentCulture = culture;
6 * * * * * *Thread.CurrentThread.CurrentUICulture = culture;
7 * * * * *}
8 * * * *}

Because of code line 3 I always get an error on my profile provider:

1 * * * *public static Profile Get() {
2 * * * * *return Create(Membership.GetUser().UserName) as Profile;
3 * * * *}

The error is on line 2 and says:

"Object reference not set to an instance of an object. Use the new
keyword to create an object instance."

What am I doing wrong?

Thanks,

Miguel
I changed my code to the following and debbuged it:

Profile profile = Profile.Get(User.Identity.Name);
CultureInfo culture = profile.Visitor.Culture;

Now profile is defined but Visitor is null ... So now I have the same
error, "Object reference not set to an instance of an object." on code
line 2.

The user is an anonymous user and it is the first time that accesses
the web site so it is normal that none of the profile properties have
been defined.

How should I prevent this error?

Thanks,

Miguel
Oct 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.