silverlight-5.0init-parameters

Silverlight 5 initParams Count always equals 0


I've see this article here on stack and this article on Silverlight MSDN, but they don't address Silverlight5. See below for my html host document div code, and C# code to call it. I get a "The given key was not present in the dictionary." error every time, and the .InitParams property count is 0 every time as well. Does someone know a solution for this? I feel like this is a bug in Silverlight5 or something. Also, if someone has a nice clean alternative way of getting info from the host html object tag - I would entertain that as well.

Markup:

<div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="300">
          <param name="source" value="ClientBin/MySilverlightApplication.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="5.0.61118.0" />
          <param name="autoUpgrade" value="true" />
          <param name="initParams" value="rootLocation=someLocation" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object>
        <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
   </div>

C# retrieval from static property:

private const String rootLocation= "rootLocation";

internal String RootLocation { 

    get
    {

        String location = App.Current.Host.InitParams[rootLocation];

        return location;

    }
}

C# retrieval from AppStartUp event:

private const String rootLocation= "rootLocation";

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MainPage();

    String location = e.InitParams[rootLocation];

}

Solution

  • I had the same problem following an upgrade of a solution to Silverlight 5. Turned out that although app.xaml was being called, the WEB project had lost its "Startup Project" status. Resetting this caused everything to work again.