Silverlight 4 Dataportal BeginFetch crashes

Silverlight 4 Dataportal BeginFetch crashes

Old forum URL: forums.lhotka.net/forums/t/11160.aspx


AKaplan posted on Tuesday, February 14, 2012

Can someone please tell me why I get an error of 

System.Windows.Markup.XamlParseException occurred

  LineNumber=8

  LinePosition=35

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

  StackTrace:

       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'.

       StackTrace:

            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()

       InnerException: 

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)

                                      .BeginFetch()

                                  End With

                                  RaiseListChangedEvents = True

                              End Sub

        bw.RunWorkerAsync()

    End Sub

 

JonnyBee replied on Tuesday, February 14, 2012

Hi,

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