Having trouble wiring up login for Silverlight.

Having trouble wiring up login for Silverlight.

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


Dane posted on Thursday, July 01, 2010

CSLA 4 beta 3, Silverlight 4, .net 4

I've been trying to mimic the login mechanism in the Rolodex application but I'm having no luck.  My principle class has a Login method (in Silverlight) as follows:

public static void Login(UsernameCriteria criteria, EventHandler<EventArgs> eventHandler)
{
 AppIdentity.GetIdentity(
                criteria,
                (o, e) =>
                {
                    if (e == null) { SetPrincipal(null); }
                    else { SetPrincipal(e.Object); }
                    eventHandler(null, EventArgs.Empty);
                });
}

AppIdentity.GetIdentity in Silverlight looks like this:

public static void GetIdentity(UsernameCriteria criteria, EventHandler<DataPortalResult<AppIdentity>> eventHandler)
{
    DataPortal<AppIdentity> dataPortal = new DataPortal<AppIdentity>();
    dataPortal.FetchCompleted += eventHandler;
    dataPortal.BeginFetch(criteria);
}

I'm using ObjetFactories and I've verified that the Fetch method of the IdentityFactory is indeed getting called however the EventArgs (e) in the Priciple's Login method is always coming back null.  It appears the callback isn't wired up correctly.  I'm obviously missing something but I'm at a loss.

Any help you can provide will be greatly appreciated.

Thanks,

Dane R. Vinson

Dane replied on Friday, July 02, 2010

Well, either I haven't provided enough information for anyone to make a guess, I've done something so stupid that no one wants to respond or everyone else is on vacation as well but I'm the only one who likes to program on vacation.

RockfordLhotka replied on Sunday, July 04, 2010

You are saying that the 'e' parameter in the callback lambda is null? That should never happen. I just scanned through the relevant code in DataPortal<T> and WcfProxy, and I can't see where it is possible that this would occur.

Can you put a breakpoint in Csla.DataPortalClient.WcfProxy.proxy_FetchCompleted() and walk through that code - that's where that object is created.

Dane replied on Sunday, July 04, 2010

I went back and starting looking as you suggested and discovered e was indeed returning a value (I swore it wasn't at one point) but e.Object is always null.  After several hours more debugging I suddenly got and exception from the AppIdendity ObjectFactory's Fetch method.  I put a try/catch around the Activator.CreateInstance call and found this exception relating to a property I'd implemented on AppIdentity:

"Can not register property UserId after containing type (CslaIdentity) has been instantiated"

After further searching on the forums I found that calling RegisterProperty with a different overload solved the exception (something to do with CslaIdentity, the base class, not being generic).  There are two strange pieces of data in this whole process.  1.  ASP.net Developer Server was only catching the exception about 1% of the time (I've only see in twice in hundreds of test runs).  2. This exception ONLY occurs when called from Silverlight.  I have a console app entry point that allowed me to log in without exception.  This second condition is very perplexing to me as the exception is occuring in the ObjectFactor which is server side only.

Anyway, it appers I'm finally able to log in from a Silverlight app now as well.

Copyright (c) Marimer LLC