The given key was not present in the dictionary

Nov 3, 2009 at 5:36 AM

Hi, I just started developing in silverlight about two months ago, and am trying to figure out how to fix this.  When I open your project fresh and run it, everything works fine, but when I build the project then run it, this pops up on load. at 100% on both localhost (windows 7 64bit) and my webhost (bluehost - linux servers).  

Occurs in app.xaml.cs with:

Uri uri = new Uri(HtmlPage.Document.DocumentUri, HttpUtility.UrlDecode(e.InitParams["UploadPage"]));

 

here is the exception:

 

{System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at FileUpload.App.Application_Startup(Object sender, StartupEventArgs e)
   at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

{System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

   at System.ThrowHelper.ThrowKeyNotFoundException()

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at FileUpload.App.Application_Startup(Object sender, StartupEventArgs e)

   at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)

   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

 

Thank you much! :) 

 

Coordinator
Nov 3, 2009 at 2:21 PM

This means that the value for e.InitParams["UploadPage"] is not set.  The url to the upload page is passed in through InitParams.  You need to set this on the page hosting silverlight control.

Hope this helps,

Darick

Aug 15, 2010 at 5:03 PM

If you launch the silverlight control from a html page then you need to add a param for initParams " <param name="initParams" value="UploadPage=FileUpload.ashx,Filter=Images (*.jpg)|*.jpg" />" in the html code. See example below:

 <div id="silverlightControlHost">
		<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
			<param name="source" value="ClientBin/FileUpload.xap"/>
			<param name="onerror" value="onSilverlightError" />
			<param name="background" value="white" />
			<param name="minRuntimeVersion" value="2.0.31005.0" />
			<param name="autoUpgrade" value="true" />
            <param name="initParams" value="UploadPage=FileUpload.ashx,Filter=Images (*.jpg)|*.jpg" />
			<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
     			<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
			</a>
		</object>
		<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>