Silverlight 4 Dataportal BeginFetch crashes

Silverlight 4 Dataportal BeginFetch crashes

Old forum URL:

AKaplan posted on Tuesday, February 14, 2012

Can someone please tell me why I get an error of 

System.Windows.Markup.XamlParseException occurred



  Message=The invocation of the constructor on type 'Designer.ViewModel.MainPresenter' that matches the specified binding constraints threw an exception. [Line: 8 Position: 35]


       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)

  InnerException: System.InvalidCastException

       Message=Unable to cast object of type 'System.InvalidOperationException' to type 'Csla.DataPortalException'.


            at Designer.ViewModel.ViewModel`1.OnError(Exception err)

            at Csla.Xaml.ViewModelBase`1.set_Error(Exception value)

            at Csla.Xaml.ViewModelBase`1.BeginRefresh(Action`1 factoryMethod)

            at Designer.ViewModel.ProductCategoryList_ViewModel..ctor()

            at Designer.ViewModel.MainPresenter..ctor()


Is this the proper way to setup your DataPortal methods for WCFProxy? 

Public Shared Sub BeginGetList(cb As EventHandler(Of DataPortalResult(Of T)))

        DataPortal.BeginFetch(Of T)(cb)

    End Sub

<EditorBrowsable(EditorBrowsableState.Never)> _

    Public Sub DataPortal_Fetch(handler As LocalProxy(Of T))

        Dim bw As New BackgroundWorker

        AddHandler bw.DoWork, Sub(o, e)

                                  RaiseListChangedEvents = False

                                  With New WcfProxy(Of T)


                                  End With

                                  RaiseListChangedEvents = True

                              End Sub


    End Sub


JonnyBee replied on Tuesday, February 14, 2012


You cannot use the BackgroundWorker in your DataPortal_Fetch.

DataPortal.BeginFetch wil start asyncronousl (ie: your code in DataPortal_Fetch is already running asyncronously) and you must supply the WcfProxy<T>.BeginFetch with the callback handler that you get as parameter to the method. 

Search the Samples download for WcfProxy - cant remember which but there should be some sample on this.

AKaplan replied on Tuesday, February 14, 2012

Yea that makes sense. I hate it when my brain takes a coding dump.

Copyright (c) Marimer LLC