Null object exception

Added null check to avoid unhandled exception crashing VS.
Merge pull request #861 from DotNetSparky/master

Null object exception