Csla.ApplicationContext.User unexpected side effect

Csla.ApplicationContext.User unexpected side effect

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


Calin posted on Wednesday, February 03, 2010

Hi, I found a very interesting issue that I managed to extract in 2 tests: [TestMethod] public void CanUserLogin() { using (var context = GetContext()) { OncarePrincipal.Login( (sender, args) => { OncarePrincipal oncarePrincipal = new OncarePrincipal(args.Object); Csla.ApplicationContext.User = oncarePrincipal; context.Assert.IsNotNull(args.Object); context.Assert.Success(); }, new UsernameCriteria("testrandomname", "randomname")); } } This first test does a user login [TestMethod] public void Simple() { using (var context = GetContext()) { UserList.GetList((sender, args) => { context.Assert.IsNull(args.Error); context.Assert.Success(); }); } } This one gets a list of users. No for some weird reason if I run the login first and the the list getter I get a error "No parameterless constructor defined .... " And not it get really interesting. If I pull out this line: Csla.ApplicationContext.User = oncarePrincipal; It all works perfect. I might add I am usign CSLA 3.8.2, and Csla.ApplicationContext.User is used only on the line I have here. Everything else is a 3 tier application. Any help with this one will be greatly appreciated ! Thank you,

RockfordLhotka replied on Wednesday, February 03, 2010

This is CSLA .NET for Silverlight?

Your custom principal must have a public default constructor for MobileFormatter to serialize it. And it will be serialized when the data portal is used, because the data portal sends the principal to the server so the server-side code runs in the same security context as the client.

Calin replied on Wednesday, February 03, 2010

I bet you get this a lot, but I am going to say it anyway

Rocky your a genius :)

It works perfect.

Copyright (c) Marimer LLC