Monday 21 July 2014

Composite UI Application Block (CAB) - Presenter is null - NullReferenceException

Problem:
While using the Composite UI Application Block (CAB), we encountered a NullReferenceException while accessing the Presenter property in one of our views. We were accessing the Presenter in the OnLoad() method of our view and strangely, the Presenter was not dependency injected on "time" hence generating an exception.

Cause:
We were initializing some UI controls in ours view's constructor. This was triggering the OnLoad() event of our view even if the Presenter property was not yet injected.

Solution:
We move the UI control initialization in the OnLoad() event.

No comments: