I recently created a new instance of my personal site on the same server as the actual site. The new instance is the "last" configuration, so it got all the new features of the last build I'm working on. In the last build, I switched Target Framework to 3.5 from 2.0 as the only really important change since the compiled elements go.
On all member pages and some other pages and some user controls, I call one or both of these two elements, each of which fails and causes an error Object reference not set to an instance of an object. But not on every page!
public static string CurrentUserName
{
get
{
string userName = "";
if (HttpContext.Current.User.Identity.IsAuthenticated)
userName = HttpContext.Current.User.Identity.Name;
return userName;
}
}
public static string CurrentUserID
{
get
{
string userID = "";
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser();
userID = user.ProviderUserKey.ToString();
}
return userID;
}
}
With stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
isClasses.BizObjects.get_CurrentUserID() in C:\My Dropbox\Trunk\Classes\BizObjects.cs:39
TheImageStore_Profile..ctor() in w:\dev\Member\Profile.aspx.cs:9
ASP.member_profile_aspx..ctor() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.0.cs:0
__ASP.FastObjectFactory_app_web_profile_aspx_48943a5b_w8t4pvz5.Create_ASP_member_profile_aspx() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.2.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
, IIS 7 2008 , Visual Studio 2008. IIS , . , ?
Target Framework 2.0 . , , , .