2

I have a silverlight application which I am having an issue with.

The page works great when loaded up normally - either through a web browser or when its installed to desktop. The problem comes in the browser, when someone hits refresh.

When they hit refresh (F5) no data is loaded, the controls render but the data-bound ones are empty. And they have a javascript error which appears at the bottom of IE.

Webpage error details

Message: Unhandled Error in Silverlight Application Provide value on 'System.Windows.Data.Binding' threw an exception. [Line: 74 Position: 57] at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name) at MS.Internal.XcpImports.DataTemplate_LoadContent(DataTemplate template) at System.Windows.Controls.DataGridTemplateColumn.GenerateElement(DataGridCell cell, Object dataItem) at System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell) at System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column) at System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow) at System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext) at System.Windows.Controls.DataGrid.InsertElementAt(Int32 slot, Int32 rowIndex, Object item, DataGridRowGroupInfo groupInfo, Boolean isCollapsed) at System.Windows.Controls.DataGrid.InsertRowAt(Int32 rowIndex) at System.Windows.Controls.DataGridDataConnection.NotifyingDataSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Data.PagedCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) at System.Windows.Data.PagedCollectionView.ProcessAddEvent(Object addedItem, Int32 addIndex) at System.Windows.Data.PagedCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) at System.Windows.Data.PagedCollectionView.<.ctor>b_0(Object sender, NotifyCollectionChangedEventArgs args) at System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection1.InsertItem(Int32 index, T item) at System.Collections.ObjectModel.Collection`1.Add(T item) at MyProject.Silverlight.MyViewModel.b_3(Object Param, GetDataCompletedEventArgs EventArgs) at MyProject.Silverlight.WebServicesSVC.WebServicesClient.OnGetDataCompleted(Object state) Line: 1 Char: 1 Code: 0

If the [Line: 74 Position: 57] is from the xaml file, then the error is the middle line of:

<sdk:DataGridTemplateColumn Header="Edit Details">
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Button Command="{Binding UpdateCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding}" Content="Update" />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

ie, the [Button...] line, position 57 is where the "{Binding..}" starts in the Command=.

-- As I say this only happens when the page is refreshed using IE's refresh button, and it happens every time on multiple PC's.

Additional details: Internet Explorer 8 Client PCs: Windows XP Hosting Server: Windows Server 2005 (or 2003 if there is no such thing as 2005). Silverlight 4

Can anyone shed any light on what is wrong? How is a refresh handled differently from just loading the page normally?

Town
  • 14,706
  • 3
  • 48
  • 72
jb.
  • 1,848
  • 9
  • 27
  • 43
  • Refreshing the page is faster than first time loading so it may be a timing issue. Where is your data coming from? How is it populated? – iCollect.it Ltd Jun 14 '11 at 15:52
  • @jb I wrote a very small HelloWorld to see if it is something special Silverlight is doing and it is not. F5 does bring my data properly. Is it possible to share some of the code so I can try to duplicate the problem? – Nair Jun 14 '11 at 17:59
  • The page is populated by a few WCF services; I have a few pages in the application, and only one of them fails (the one which does have 4-5 service calls for pulling data back). – jb. Jun 15 '11 at 15:16
  • I can try and post some code, but its a very large project, with a few databases and such. It may take a while to pull out a smaller section which replicates the problem... – jb. Jun 15 '11 at 15:20
  • I did some testing with Fiddler and I can confirm the WCF service is definately returning the data. It's just not being rendered. – jb. Jun 16 '11 at 14:23
  • IE refresh is suppose to behave the same way as application start up. I wrote a small code with RIA services and both application startup and refresh rendered the data correctly. The question then is going back to what @HiTechMagic referring to the timing issue? Are you binding data to a property in a VM? Are you return null if it does not have value? Are you raising property changed event after load completes? Just asking question, that might help look at the code differently. – Nair Jun 16 '11 at 15:52

1 Answers1

0

When I get javascript errors in the deployed version of my silverlight project, it almost always is my application's logic problem in the behind code. YMMV.

Given you have SL4, you probably can't place debug point in XAML. I felt like mentioning SL5 beta on a different box with your code deployed to gain that feature to assist in debugging.

Alternatively, you could refresh in software per:

Can Silverlight initiate Page Refreshes?

and then see if your app behaves differently.

Community
  • 1
  • 1
gsvolt
  • 184
  • 8