Null Reference Exception

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
12/30/2011 6:45:17 AM
Gravatar
Total Posts 68

Null Reference Exception

Hi Joe,

Seeing several of these exceptions in the log this morning. If I can lock down on a repro I'll post.

2011-12-30 04:25:47,008 ERROR - en-US - /Default.aspx - mojoPortal.Web.mojoBasePage - en-US - /Default.aspx System.NullReferenceException: Object reference not set to an instance of an object.    at mojoPortal.Web.mojoRoleProvider.GetRolesFromCookie()    at mojoPortal.Web.mojoRoleProvider.GetRolesForUser(String userName)    at System.Web.Security.RolePrincipal.IsInRole(String role)    at mojoPortal.Business.WebHelpers.WebUser.IsInRole(String role)    at mojoPortal.Business.WebHelpers.WebUser.IsInRoles(String roles)    at mojoPortal.Web.SiteUtils.GetSkinName(Boolean allowPageOverride, Page page)    at mojoPortal.Web.mojoBasePage.SetupMasterPage()    at mojoPortal.Web.mojoBasePage.OnPreInit(EventArgs e)    at mojoPortal.Web.UI.CmsPage.OnPreInit(EventArgs e)    at System.Web.UI.Page.PerformPreInit()    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

MP 2.3.7.6/.NET 4/MSSQL/Full Trust

12/30/2011 7:15:23 AM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Hi Bill,

Did you change your machinekey in Web.config? That could be a factor if you did.

Do you have per user skins enabled? That uses a cookie to keep track of the user skin.

I've tried a few things to reproduce the problem here but no luck, so let me know if you figure out steps to cause it.

Best,

Joe

12/30/2011 7:55:18 AM
Gravatar
Total Posts 68

Re: Null Reference Exception

No repro but a little more information. The user seeing this accessed the site using a Silk browser. Said he hit the site and authententicated using a federated credential to sign in and took the exception. Subsequent accesses to the site also took the exception. He cleared the browser cookies and now can access and repeat the original steps above.

The machine key is correct and per user skins are not enabled but this user is a content admin so I believe he would have the option to use but has Site Default selected in his profile. For now will just keep an eye on the log.

Thanks Joe.

 

12/30/2011 8:07:03 AM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Hi Bill,

My understanding is that Silk browser is the one Amazon uses in their kindle tablets and they do some wierd things like caching everything on their own servers to make it faster and reduce the actual bandwidth used by the devices, so the device is requesting content from the amazon servers instead of directly from the web site. I don't have one of those devices and if I did it is still doubtful that I could solve the problem since what they do on their servers is beyond anything I can control.

Best,

Joe

12/30/2011 8:27:51 AM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Hi Bill,

Actually I can put a catch for that null reference exception in there though it is unclear to me what could be null since we are checking for null on all relevant things in this code:

public override string[] GetRolesForUser(string userName)
{
if (HttpContext.Current != null)
{

SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
string roleCookieName = SiteUtils.GetRoleCookieName(siteSettings);

if ((HttpContext.Current.Request.IsAuthenticated)
&& (HttpContext.Current.User.Identity.Name == userName)
&&(siteSettings != null)
)
{

if (
(CookieHelper.CookieExists(roleCookieName))
&& (CookieHelper.GetCookieValue(roleCookieName).Length > 0)
)
{
try
{
return GetRolesFromCookie();

// the below errors are expected if the machine key has been changed and the user already has a role cookie
// apparently the update for http://weblogs.asp.net/scottgu/archive/2010/09/28/asp-net-security-update-now-available.aspx
// changed it from throwing a CryptographyException to an HttpException
}
catch (System.Security.Cryptography.CryptographicException)
{
return GetRolesAndSetCookie();
}
catch (HttpException)
{
return GetRolesAndSetCookie();
}
}
else
{
return GetRolesAndSetCookie();
}

}
else
{
// not current user or not authenticated

if ((siteSettings != null) && (userName != null) && (userName.Length > 0))
{
return SiteUser.GetRoles(siteSettings, userName);
}
}
}

return new string[0];

}

I'll add a catch for nullreferenceexception there for the next release so it won't crash the page but it still could have unexpected results (and you'll still see it in the logs because I don't want to swallow an error without logging it). Its like having a weird proxy server in between the browser and the actual web site. 

You might ask the user to try it with the acceleration disabled since some people are reporting it is actually faster without it enabled.

Best,

Joe

12/30/2011 11:36:51 AM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Hey Bill,

Did you install the latest windows update released our of band to fix this asp.net DOS vulnerability?

I just installed it and now I am getting this error on this site. I put in the try catch to solve the error but looking further into it now.

Best,

Joe

12/30/2011 11:39:50 AM
Gravatar
Total Posts 68

Re: Null Reference Exception

Yes I just checked the ISP outage site and they did apply that critical fix last night. All the errors happened after that time.

12/30/2011 11:43:56 AM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Thanks, I think something must have changed in that update. I'm going to apply it now to my local machine and see if I can get the problem to happen and step through the code to find out what exactly is null.

It started happening on this site right after I applied the update to this server.

Best,

Joe

12/30/2011 12:11:54 PM
Gravatar
Total Posts 18439

Re: Null Reference Exception

Hi Bill,

I still was not able to get the error to happen on my local machine but the error handler seems to be working with no side effects on this site.

I wonder if you could help me verify the fix, the steps would be:

1. make sure your user can still produce the problem.

2. I'll send you a patched mojoPortal.Web.dll (you're using .NET 4 right?) and you replace your exisitng one.

3. verify the user can no longer produce the problem

If we can verify the fix then I'll go ahead and patch the 2.3.7.6 release so no-one else gets this error going forward.

Could you help with that ?

Thanks,

Joe

12/30/2011 12:26:40 PM
Gravatar
Total Posts 68

Re: Null Reference Exception

Sure Joe Happy to help.

The user just tried the same steps on the Kindle and says where the Janrain control is located to federate he sees "Status 500: Internal Server Error Content-Type: text/html    500 Internal Server Error." I'm seeing the error in the log so I guess that I can verify the fix.

-Bill

12/30/2011 1:14:39 PM
Gravatar
Total Posts 68

Re: Null Reference Exception

Looks good so far Joe.

The Janrain control consistently appears and the user can hit the site and repeatedly sign-in with federated credentials. The Kindle is happy browsing the site in both AWS accelerated and non-accelerated mode.

Thanks for chasing this down on the start of a long holiday weekend.

Should be around today and I'll keep an eye on the log.

-Bill

 

You must sign in to post in the forums. This thread is closed to new posts.