Fixed a rare NullReferenceException in CanUnload

see the stacktrace at #5528.