I’ve been posting so much about the awesome LightSwitch HTML client lately (have you seen the second season of Leading LightSwitch by the way?) that you might get the impression that I’m now an HTML-Hipster exclusively…
No way, and as a tribute to my love to the strongly typed world (also just because it’s really cool) I’m going to challenge your LightSwitch haxpert level with a coding riddle…
I have a normal LightSwitch screen, that has a local property (from Screen Designer > Add data item > Local property: UserRegistration(Entity) ) and a fancy custom user control. From the screen’ Created method, I’m trying to bind an event handler to an event on this fancy custom user control that is supposed to instantiate the local UserRegistration property, then show a modal popup. Nothing extraordinary, one would think when looking at the code:
This code actually throws a NullReferenceException at line 15 (much to my own initial surprise)… I verified this by putting up a breakpoint, and indeed, ‘this.NewUserRegistration’ returns null even though we just assigned the return value of the AddNew method on line 14!!
Your mission, should you choose to accept it: explain why, and propose a fix. The rules of the challenge are simple: the first one to post the correct answer wins, he/she doesn’t actually win anything (I’m completely broke after giving away $10.000 last month), and you are excluded from entering the competition if your name is Matt Evans, Huy Nguyen, … ( or if you share a whiteboard with any of these guys).
As always, should any member of your team be caught or killed, the Secretary will disavow all knowledge of your actions.
Keep rocking LS!