Button_Click to Fetch Data using CslaDataProvider in MainPage.xaml returns only Error

Button_Click to Fetch Data using CslaDataProvider in MainPage.xaml returns only Error

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


Jav posted on Sunday, October 25, 2009

using Csla 3.8.0 for a Silverlight project. I am trying to follow the NTierArch video.

My object graph loads just fine using a call to:
public static EFrame GetEFrame()
{
return DataPortal.Fetch();
}
in the FrameLibrary.Server.

However, trying to use code in FrameLibrary.Client from MainPage.xaml gives me an error. Here is what I have in the MainPage.xaml

Csla:ErrorDialog x:Key="DataErrorDialog"
DialogTitle="=Error"
DialogFirstLine="An Error Has Occured"
ShowExceptionDetail="False" />

Csla:CslaDataProvider x:Key="data"
ObjectType="FrameLibrary.EFrame, EFrame"
ManageObjectLifetime="True"
FactoryMethod="GetEFrame"
DataChangedHandler="{StaticResource DataErrorDialog}"
IsInitialLoadEnabled="True" />

Button Width="75" Csla:InvokeMethod.TriggerEvent="Click"
Csla:InvokeMethod.Target="{StaticResource data}"
Csla:InvokeMethod.MethodName="EFrame.GetEFrame"
Content="Get Frame" />

Here is the error:

[Main Instruction]
An unhandled exception ('Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.NullReferenceException: Object reference not set to an instance of an object.
at Csla.Silverlight.InvokeMethod.CallMethod(Object sender, EventArgs 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)
') occurred in iexplore.exe [6016].


It looks like my code in FrameLibrary.Client is not even called.

Would appreciate some suggestions.
Javed

RockfordLhotka replied on Sunday, October 25, 2009

It is possible that you hit a Beta 1 bug. Please try with Beta 2 (just released) and see if the problem still exists.

Jav replied on Monday, October 26, 2009

I am now using 3.8.0 beta2
Thank you for refreshing the sample code for 3.8 - it should be immensely helpful.

It is possible that my problem is my lack of complete understanding of how things are supposed to work.

Here is my CslaDataProvider:

Csla:CslaDataProvider x:Key="data"
ManageObjectLifetime="True"
IsInitialLoadEnabled="True"
ObjectType="FrameLibrary.EFrame, FrameLibrary, Version=..., Culture=neutral, PublicKeyToken=null"
FactoryMethod="GetEFrame" />

Here is the Button that I want to click to fetch the object graph (this is just to test the process):

StackPanel Height="24"
Width="312"
Canvas.Left="34"
Canvas.Top="575"
Orientation="Horizontal"
DataContext="{Binding Source={StaticResource data}}">
Button Width="75"
Csla:InvokeMethod.TriggerEvent="Click"
Csla:InvokeMethod.MethodName="GetEFrame" ******************************
Content="Get Frame" />


I added the ***** to mark the line where I am getting the following error:

AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 631 Position: 54]

It looks like the only acceptable MethodName values are Cancel, Delete and Save, everything else generates that error.

Also my CslaDataProvider is marked IsInitialLoadEnabled="True". But my GetEFrame method is not called (method has a breakpoint which is never hit)

Thanks for your help.

Javed

RockfordLhotka replied on Monday, October 26, 2009

InvokeMethod invokes a method on the current DataContext. Obviously the
method you want to invoke must be implemented on that DataContext.

Your DataContext is the data provider control, and the standard
CslaDataProvider control doesn't implement a method called GetEFrame, so you
should get an exception for trying to use a method that doesn't exist.

Jav replied on Monday, October 26, 2009

Thanks Rocky.

Obviously I have some reading to do.

Javed

RockfordLhotka replied on Monday, October 26, 2009

If you want to load data, the Refresh() method on CslaDataProvider is what triggers the data provider to call the object's factory method. You can use InvokeMethod to call Refresh.

Copyright (c) Marimer LLC