0

Using HtmlPage.RegisterScriptableObject("Shell", serviceLocator.GetInstance<Shell>());

gives me a null warning. How can I make this go away?

2 Answers2

0

The warning is that serviceLocator is null?

Without seeing any more of your code (to get an idea of what other contracts might be in play), you could put

Contract.Assume(serviceLocator != null);

on the line above.

Jeremy Todd
  • 3,261
  • 1
  • 18
  • 17
0

Perhaps serviceLocator.GetInstance<Shell>() returns null if an instance is not found.

Try providing an alternative control flow for that situation.

var instance = serviceLocator.GetInstance<Shell>();
if (instance == null)
    throw new InvalidOperationException("Shell instance is missing.");
HtmlPage.RegisterScriptableObject("Shell", instance);
Jeffrey L Whitledge
  • 58,241
  • 9
  • 71
  • 99