Unhandled Error in Silverlight Application Code: 4004

Answered (Verified) This post has 2 verified answers and 9 replies

Not Ranked
Posts: 15
HenryBrightstar Posted: Wed Sep 30, 2009 @ 5:15 PM
I was following the quickstart directions for the Silverlight Upload control.

After selecting a file and clicking on Upload Files button the silverlight app crashes and Visual Studio pops up with the message below and asks me to select a debugger.

Unhandled Error in Silverlight Application Code: 4004.
Category ManagedRuntimeError
Message System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary

After that the silverlight app is no longer running and my screen is blank.

Has anyone else experienced this and know if either some step is missing from the quickstart?

<navigation:Page 
    x:Class="Brightstar.Silverlight3.LookAndFeel.Upload" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
       xmlns:ComponentArtInput="clr-namespace:ComponentArt.Silverlight.UI.Input;assembly=ComponentArt.Silverlight.UI.Input"
            xmlns:ComponentArt="clr-namespace:ComponentArt.Silverlight.UI.Navigation;assembly=ComponentArt.Silverlight.UI.Navigation"
      xmlns:ComponentArtCommon="clr-namespace:ComponentArt.Silverlight.UI.Utils;assembly=ComponentArt.Silverlight.UI.Common"
        xmlns:ComponentArtData="clr-namespace:ComponentArt.Silverlight.UI.Data;assembly=ComponentArt.Silverlight.UI.Data"
     xmlns:ComponentArtTheming="clr-namespace:ComponentArt.Silverlight.UI;assembly=ComponentArt.Silverlight.UI.Common"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    Title="Upload">

    <navigation:Page.Resources>
        <ComponentArtTheming:Theme x:Key="UploadTheme" 
                      BaseSource="/ComponentArt.Silverlight.UI.Data;component/Themes/generic.xaml" 
                      Source="/ComponentArt.Silverlight.Themes.Office2007;component/Upload.xaml"  />
    </navigation:Page.Resources>

    <Grid x:Name="LayoutRoot" Style="{StaticResource PageGridStyle}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Style="{StaticResource PageHeaderStyle}" >
            <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" Text="Upload"/>
        </Border>

        <Border Grid.Row="1" Style="{StaticResource PageBorderStyle}" >
            <ScrollViewer  x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" >

                <StackPanel x:Name="ContentStackPanel" Style="{StaticResource ContentStackPanelStyle}">


                        <ComponentArtData:Upload
			                x:Name="upload1"
			                Height="508"
			                Width="560" />


                </StackPanel>

            </ScrollViewer>
        </Border>

    </Grid>
</navigation:Page>







Answered (Verified) Verified Answers

Not Ranked
Posts: 6
Answered (Verified) aharris Posted: Fri Oct 16, 2009 @ 9:15 AM
Verified by stephen
I put in a support request and found recieved the following solution:

 I see what's wrong- you're missing the silverlight server control on the aspx page (see ms-help://ComponentArt.UIFramework.2009.2/ComponentArt.Web.UI.Silverlight/Upload_QuickStart.htm in the local docs). I modified the SilverlightApplication1TestPage.aspx in the project you sent thusly: 


  <%@ Register Assembly="ComponentArt.Silverlight.Server" Namespace="ComponentArt.Silverlight.Server" TagPrefix="ComponentArt" %>
<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>

 

    <form id="form1" runat="server" style="height:100%">
 

  <asp:ScriptManager runat="server" ID="sc"></asp:ScriptManager>
    <div id="silverlightControlHost">
   
     <ComponentArt:SilverlightUpload ID="upload1" runat="server"
      MaximumFileCount="8"
      MaximumUploadSize="0"
      TempFileFolder="~/uploadtemp"
      DestinationFolder="~/Upload"
      OverwriteExistingFiles="true"
      SilverlightControlId="Xaml1" />

    <asp:Silverlight
             ID="Xaml1"
             runat="server"
             Source="ClientBin/SilverlightApplication1.xap"
             MinimumVersion="2.0.31005.0"
             Width="100%" Height="100%"
             Windowless="true"
             />
   
  
    </form>

Top 10 Contributor
Posts: 6,694
Answered (Verified) stephen Posted: Fri Jun 3, 2011 @ 10:54 AM
Verified by stephen

If I'm reading this right- that you're modifying the columns of the datagrid control at runtime- then I'm afraid this is a known limitation of the control- columns can only be defined once, I'm afraid, and can't be destroyed/ redefined later. 

Stephen Hatcher, Developer Support Manager

All Replies

Not Ranked
Posts: 6
aharris Posted: Wed Oct 7, 2009 @ 2:52 PM
I am having the same issue.. 

my silverlight upload control displays  properly, and lets me select files to upload. Then when I click on upload. It crashes with the error that you mentioned. 
Then. IE gives the following Error:

 Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; FDM)
Timestamp: Wed, 7 Oct 2009 21:52:34 UTC
Message: Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: 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 ComponentArt.Silverlight.UI.Data.UploaderModule.InitialResponseCallback()
   at ComponentArt.Silverlight.UI.Data.UploaderModule.StartUpload(String tag)
   at ComponentArt.Silverlight.UI.Data.UploadItem.StartUpload(String tag)
   at ComponentArt.Silverlight.UI.Data.Upload.doBeginUpload()
   at ComponentArt.Silverlight.UI.Data.Upload.BeginUpload()
   at ComponentArt.Silverlight.UI.Data.Upload._uploadFilesButton_Click(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)     
Line: 57
Char: 13
Code: 0
URI: http://localhost:3950/Login.aspx?ReturnUrl=%2fUploadControlTestPage1.aspx
Not Ranked
Posts: 6
Answered (Verified) aharris Posted: Fri Oct 16, 2009 @ 9:15 AM
Verified by stephen
I put in a support request and found recieved the following solution:

 I see what's wrong- you're missing the silverlight server control on the aspx page (see ms-help://ComponentArt.UIFramework.2009.2/ComponentArt.Web.UI.Silverlight/Upload_QuickStart.htm in the local docs). I modified the SilverlightApplication1TestPage.aspx in the project you sent thusly: 


  <%@ Register Assembly="ComponentArt.Silverlight.Server" Namespace="ComponentArt.Silverlight.Server" TagPrefix="ComponentArt" %>
<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>

 

    <form id="form1" runat="server" style="height:100%">
 

  <asp:ScriptManager runat="server" ID="sc"></asp:ScriptManager>
    <div id="silverlightControlHost">
   
     <ComponentArt:SilverlightUpload ID="upload1" runat="server"
      MaximumFileCount="8"
      MaximumUploadSize="0"
      TempFileFolder="~/uploadtemp"
      DestinationFolder="~/Upload"
      OverwriteExistingFiles="true"
      SilverlightControlId="Xaml1" />

    <asp:Silverlight
             ID="Xaml1"
             runat="server"
             Source="ClientBin/SilverlightApplication1.xap"
             MinimumVersion="2.0.31005.0"
             Width="100%" Height="100%"
             Windowless="true"
             />
   
  
    </form>

Not Ranked
Posts: 1
Answered (Not Verified) skotl Posted: Tue May 25, 2010 @ 5:45 PM
Suggested by skotl
When you get an exception code 4004, then then it is most likely that the exception has fallen outside the debugger. In this case, you need to detach the running debgugger and progress from there. I document this, along with the most likely cause (not capturing validation exceptions) here.

Regards
   Scott
Top 50 Contributor
Posts: 100
tomaten Posted: Mon Jun 14, 2010 @ 9:16 AM
I get also this error:

Error:Unhandled Error in Silverlight Application Der angegebene Schlüssel war nicht im Wörterbuch angegeben.   bei System.ThrowHelper.ThrowKeyNotFoundException()
   bei System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   bei ComponentArt.Silverlight.UI.Data.UploaderModule.InitialResponseCallback()
   bei ComponentArt.Silverlight.UI.Data.UploaderModule.StartUpload(String tag)
   bei ComponentArt.Silverlight.UI.Data.UploadItem.StartUpload(String tag)
   bei ComponentArt.Silverlight.UI.Data.Upload.doBeginUpload()
   bei ComponentArt.Silverlight.UI.Data.Upload.BeginUpload()
   bei ComponentArt.Silverlight.UI.Data.Upload._uploadFilesButton_Click(Object sender, RoutedEventArgs e)
   bei System.Windows.Controls.Primitives.ButtonBase.OnClick()
   bei System.Windows.Controls.Button.OnClick()
   bei System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   bei System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Not Ranked
Posts: 4
conflyto Posted: Wed Jul 7, 2010 @ 5:12 AM
I'm getting the same 4004 error, but I tryied everything as said in the help and this forum, but nathing worked.
I'm testing a basic model like this:

<UserControl x:Class="SilverlightApplication3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:my="clr-namespace:ComponentArt.Silverlight.UI.Data;assembly=ComponentArt.Silverlight.UI.Data">

    <Grid x:Name="LayoutRoot" Background="White" Height="300" Width="400">
        <my:Upload Height="300" HorizontalAlignment="Left" Name="upload1" VerticalAlignment="Top" Width="400"
                UploadGroupFailed="Upload_UploadGroupFailed" UploadGroupSuccess="Upload_UploadGroupSuccess"
                UploadItemFailed="Upload_UploadItemFailed" UploadItemSuccess="Upload_UploadItemSuccess" UploadItemProgressChanged="Upload_UploadItemProgressChanged"
                UploadItemRemoved="Upload_UploadItemRemoved"  UploadGroupProgressChanged="Upload_UploadGroupProgressChanged"
                   />
    </Grid>
</UserControl>

I putted a line like this in every event:
Debug.WriteLine("Upload_UploadItemRemoved." + uce.uploadSource.FileName);

My aspx page:
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="ComponentArt.Silverlight.Server" Namespace="ComponentArt.Silverlight.Server" TagPrefix="ComponentArt" %>
<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>SilverlightApplication3</title>
    <style type="text/css">
    html, body {
	    height: 100%;
	    overflow: auto;
    }
    body {
	    padding: 0;
	    margin: 0;
    }
    #silverlightControlHost {
	    height: 100%;
	    text-align:center;
    }
    </style>

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            upload1.Uploaded += new SilverlightUpload.UploadedEventHandler(upload1_OnUploaded);
        }

        private void upload1_OnUploaded(object sender, SilverlightUpload.UploadUploadedEventArgs args)
        {
            foreach (UploadedFileInfo oInfo in args.UploadedFiles)
                oInfo.SaveAs(System.IO.Path.Combine(Server.MapPath(upload1.DestinationFolder), oInfo.FileName), upload1.OverwriteExistingFiles);
        }
    
    </script>

    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }
            
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {           
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" style="height:100%">
         <asp:ScriptManager runat="server" ID="sc"></asp:ScriptManager>
        <div id="silverlightControlHost">
            <ComponentArt:SilverlightUpload ID="upload1" runat="server"
              MaximumFileCount="8"
              MaximumUploadSize="0"
              TempFileFolder="~/Upload"
              DestinationFolder="~/Upload"
              OverwriteExistingFiles="true"
              SilverlightControlId="Xaml1" />
            <asp:Silverlight 
                     ID="Xaml1" 
                     runat="server" 
                     Source="ClientBin/SilverlightApplication3.xap" 
                     MinimumVersion="2.0.31005.0" 
                     Width="100%" Height="100%" 
                     Windowless="true"
                     />

	    </div>
    </form>
</body>
</html>
 The version I'm using is 2010.1 with VS 2010.
 
Not Ranked
Posts: 2
wisumant Posted: Thu Jun 2, 2011 @ 6:21 AM

Hi All,

I need urgent help for my project purpose. I am using a gridview. In which I am trying to insert some columns dynamically. As these columns depend on different parameters so while populating the grid different columns will be inserted. For that whenever I am populating the grid for second time ­first I am deleting the older dynamically added columns and adding the new one. But I am getting whever I am populating the grid for second time.

Below is the code I am using to dynamically ass and remove columns.

//delete old columns

                foreach (string approvalUser in tempSchemaList)

                {

                    if (((GridViewDataColumn)dgEng.Columns[approvalUser]) != null)

                     dgEng.Columns.Remove((GridViewDataColumn)dgEng.Columns[approvalUser])

                }

 

 

                //inserting new columns

               

foreach (string approvalUser in approverUsers)

                    {

 

                       

GridViewDataColumn datacolumn = new GridViewDataColumn();

                        datacolumn.Header = approvalUser;

                        datacolumn.UniqueName = approvalUser;

                        datacolumn.SortingState = SortingState.Ascending; datacolumn.DataMemberBinding = new System.Windows.Data.Binding(“ab”);

                       

Interaction.GetBehaviors(datacolumn).Add(new ClosePopupOnApplyFilterBehavior());

                        dgEng.Columns.Insert(insertIndex, datacolumn);

                        insertCount++;

                        insertIndex++;

                    }

                }

/////////////////////////

And while populating the grid for second time I am getting the following error:

 

 

Line: 57
Error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: 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 System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType) 

///////////

Please suggest what is wrong and what to do?

Top 10 Contributor
Posts: 6,694
Answered (Verified) stephen Posted: Fri Jun 3, 2011 @ 10:54 AM
Verified by stephen

If I'm reading this right- that you're modifying the columns of the datagrid control at runtime- then I'm afraid this is a known limitation of the control- columns can only be defined once, I'm afraid, and can't be destroyed/ redefined later. 

Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 2
wisumant Posted: Sat Jun 4, 2011 @ 1:39 PM
oh is It ! thanks for the quock response.
Not Ranked
Posts: 3
sneralla Posted: Mon May 21, 2012 @ 11:48 PM
Hi,

    The columns of the DataGrid can be destroyed and modified dynamically, i.e., once the data is bound to the dataGrid with a set of data, say the data grid is bound with columns CategoryName, ProductName and Quantity. 

For the second time, we can bind a new set of data to the DataGrid dynamically, i.e., different columns like EmployeeName, DOJ, Salary.

This is achieved dynamically and I could achieve it for our requirement where we can work with the DataGrid binding  new sets of data destroying/ redefining the columns generated dynamically.

Regards,

Sreedevi N
Page 1 of 1 (10 items)