Developer forum

Forum » Ecommerce - Standard features » NullReferenceException in Dynamicweb.Ecommerce.Cart.Notifications.AfterLoginSubscriber.OnNotify

NullReferenceException in Dynamicweb.Ecommerce.Cart.Notifications.AfterLoginSubscriber.OnNotify

Hans Kloppenborg
Reply

Hello,

We are getting complaints from a customer that sometimes their visitors experience a yellow exception screen with the error:

Object reference not set to an instance of an object..
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.Cart.Notifications.AfterLoginSubscriber.OnNotify(String notification, NotificationArgs args)
at Dynamicweb.Extensibility.Notifications.NotificationManager.Notify(String notification, NotificationArgs eventArgs)
in E:\agent_work\35\s\09 - Core\Dynamicweb.Extensibility\Head\Dynamicweb.Extensibility\Notifications\NotificationManager.cs:line 76
at Dynamicweb.Frontend.LogOnHandler.LogOn(String username, String password, Boolean onlyActive, Boolean impersonateUser, Int32 impersonateUserId, Boolean skipPasswordCheck)
at Dynamicweb.Frontend.LogOnHandler.CookieLogon()
at Dynamicweb.Frontend.SecurityHandler.ExtranetStart()
at Dynamicweb.Frontend.LoginHandler.ExtranetStart(Int32 pageId)
at Dynamicweb.Frontend.PageView.Load()
at Dynamicweb.Frontend.DynamicwebHttpHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I have been looking at this and when I check what code gets hit it seems that there are two lines where properties of the user get read which, as far as I know, can be null if you are not logged in. It are the following two lines:

      if (!string.IsNullOrEmpty(extranetLoginArgs.User.Currency) && Dynamicweb.Ecommerce.Services.Currencies.GetCurrency(extranetLoginArgs.User.Currency) != null)

and

      if (string.IsNullOrEmpty(extranetLoginArgs.User.CountryCode) || Dynamicweb.Ecommerce.Services.Countries.GetCountry(extranetLoginArgs.User.CountryCode) == null)

 

We tried to overriding the notificationsubscriber (and hit the null reference exceptions debugging) but it seems the original goes off too and crashes the application.

Can you suggest a solution for this problem?

Greets Hans


Replies

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hello Hans,

What DW version do you use to catch the exception? Actually, bug like that has already been fixed by TFS 65002 on DW9.7.0 and up. I was not able to reproduce the issue on solution uses Rapido template set and based on last DW9.8.8.

BR, Oleg QA 

 
Hans Kloppenborg
Reply

Hi Oleg,

We are on 9.8.2, Ecommerce.dll version 1.8.13 . Downloaded the latest 9.8.8 just to check what had changed but still see lines like

      if (!string.IsNullOrEmpty(extranetLoginArgs.User.Currency) && Dynamicweb.Ecommerce.Services.Currencies.GetCurrency(extranetLoginArgs.User.Currency) != null)

which will lead to a null reference exception if extranetLoginArgs.User is null. 

Problem with this issue is that we cannot reproduce it ourselves, only when I try to override the method with identical code and debug it the exception occurs.

Sadly our customer gets send screenshots of the yellow screen with above exception by her visitors, and had it happen to herself once also.

Is there a good reason you assume the user will never be null?

Greets Hans

 
Nicolai Pedersen
Reply

It is a AfterLoginSubscriber - so it will have a user... since it is a login.

I think it could be TFS#80608, see https://doc.dynamicweb.com/downloads/releases/bug-fixes/known-bugs, that is merging carts. If I create a cart before logging in and needs to merge it with the cart persisted on my user. It is currently being tested - not released yet.

BR Nicolai

 
Hans Kloppenborg
Reply

Hi Nicolai,

Thanks for your answer. We have our own "OnExtranetLogin" subscriber where we check if the login is still valid with an external API, and if not we log the user off (Dynamicweb.Frontend.LogOnHandler.LogOff(false) ). Could it be that this causes the user to become null, or is the order these events happen not right for that?

If you think its the known merge bug, could you keep us informed when this is fixed?

N.B. we do not use persistent carts, for each order we start a new cart, could we somehow prevent the exception by doing something before the login goes off?

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Yes, that would cause the user to become null - could be the issue. You can do a redirect after logoff.

It is more likely that your logoff is the cause and not the merge if you do not allow anonymous carts.

BR Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum