I am trying to create a test project using csla .net for silverlight 4.2.2. I used the SimpleApp sample project in VB and one server class of .Net library project and one client class of SilverLight library project and one SilverLight application for UI. When I try to create a object from server class via call by Dataportal implementatin for SilverLight, it is working correctly. Call to BeginCreate is done successfully but when i try to use the object returned by callback method, the error "NULLObjectReferenceException" error is thrown. Please refer the code below:
Server/Client object Factory and Data Access code:
#Region " Silverlight Data Access "
#If SILVERLIGHT Then
'Factory Methods starts
Public Shared Sub BeginNewPatient(ByVal proxyMode As DataPortal.ProxyModes, ByVal callback As EventHandler(Of DataPortalResult(Of Patient)))
Dim dp As New DataPortal(Of Patient)(proxyMode)
AddHandler dp.CreateCompleted, callback
dp.BeginCreate()
End Sub
Public Shared Sub BeginGetPatient(ByVal id As Guid, ByVal callback As EventHandler(Of DataPortalResult(Of Patient)))
Dim dp As New DataPortal(Of Patient)
AddHandler dp.FetchCompleted, callback
dp.BeginFetch(New SingleCriteria(Of Patient, Guid)(id))
End Sub
Public Shared Sub BeginDeletePatient(ByVal id As Guid, ByVal callback As EventHandler(Of DataPortalResult(Of Patient)))
Dim dp As New DataPortal(Of Patient)
AddHandler dp.DeleteCompleted, callback
dp.BeginDelete(New SingleCriteria(Of Patient, Guid)(id))
End Sub
Public Sub New()
' required by MobileFormatter
End Sub
'Factory Methods ends
Public Overrides Sub DataPortal_Create( _
ByVal handler As Csla.DataPortalClient.LocalProxy(Of Patient).CompletedHandler)
Dim bw As New System.ComponentModel.BackgroundWorker
AddHandler bw.DoWork, AddressOf DoCreate
AddHandler bw.RunWorkerCompleted, AddressOf DoCreateComplete
bw.RunWorkerAsync(handler)
End Sub
Private Sub DoCreate(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
e.Result = e.Argument
End Sub
Private Sub DoCreateComplete(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
Dim handler As Csla.DataPortalClient.LocalProxy(Of Patient).CompletedHandler
handler = CType(e.Result, Csla.DataPortalClient.LocalProxy(Of Patient).CompletedHandler)
Try
Using BypassPropertyChecks
Status = "Created " & ApplicationContext.ExecutionLocation.ToString
End Using
MyBase.DataPortal_Create(handler)
Catch ex As Exception
handler(Me, ex)
End Try
End Sub
#End Region
SilverLight UI Code:
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private WithEvents _provider As CslaDataProvider
Private Sub BindPatient(ByVal sender As Object, ByVal e As Csla.DataPortalResult(Of PTAppScheduler.Patient))
Dim p1 As Patient = New Patient
p1 = e.Object
p1.Name = TextBox1.Text
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim id As System.Guid
id = New Guid("866B76E9-614B-4406-98E5-18EF236C8673")
PTAppScheduler.Patient.BeginNewPatient(Csla.DataPortal.ProxyModes.Auto, AddressOf BindPatient)
End Sub
Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
End Sub
End Class
#Region
" Silverlight Data Access "
#If
SILVERLIGHT
Then
'Factory Methods starts
Public Shared Sub BeginNewPatient(ByVal proxyMode As DataPortal.ProxyModes, ByVal callback As EventHandler(Of DataPortalResult(Of Patient
)))
Dim dp As New DataPortal(Of Patient
)(proxyMode)
AddHandler
dp.CreateCompleted, callback
dp.BeginCreate()
End
Sub
Public Shared Sub BeginGetPatient(ByVal id As Guid, ByVal callback As EventHandler(Of DataPortalResult(Of Patient
)))
Dim dp As New DataPortal(Of Patient
)
AddHandler
dp.FetchCompleted, callback
dp.BeginFetch(
New SingleCriteria(Of Patient, Guid
)(id))
End
Sub
Public Shared Sub BeginDeletePatient(ByVal id As Guid, ByVal callback As EventHandler(Of DataPortalResult(Of Patient
)))
Dim dp As New DataPortal(Of Patient
)
AddHandler
dp.DeleteCompleted, callback
dp.BeginDelete(
New SingleCriteria(Of Patient, Guid
)(id))
End
Sub
Public Sub New
()
' required by MobileFormatter
End
Sub
'Factory Methods ends
Public Overrides Sub
DataPortal_Create( _
ByVal handler As Csla.DataPortalClient.LocalProxy(Of Patient).CompletedHandler
)
Dim bw As New System.ComponentModel.
BackgroundWorker
AddHandler bw.DoWork, AddressOf
DoCreate
AddHandler bw.RunWorkerCompleted, AddressOf
DoCreateComplete
bw.RunWorkerAsync(handler)
End
Sub
Private Sub DoCreate(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs
)
e.Result = e.Argument
End
Sub
Private Sub DoCreateComplete(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs
)
Dim handler As Csla.DataPortalClient.LocalProxy(Of Patient).
CompletedHandler
handler =
CType(e.Result, Csla.DataPortalClient.LocalProxy(Of Patient).CompletedHandler
)
Try
Using
BypassPropertyChecks
Status =
"Created " & ApplicationContext
.ExecutionLocation.ToString
End
Using
MyBase
.DataPortal_Create(handler)
Catch ex As
Exception
handler(
Me
, ex)
End
Try
End
Sub
#End
Region
Copyright (c) Marimer LLC