Csla4.0 Breaking Change from Csla 3.8.4

Csla4.0 Breaking Change from Csla 3.8.4

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


Jav posted on Monday, July 26, 2010

I may have finally found the "Source of my discontent" in the last few days. (Ref: http://forums.lhotka.net/forums/t/9253.aspx)

For those who didn't read my rant in that thread, here is the brief narrative.  I converted my VS08, .Net3.5, SL3 project to VS10, .Net4, SL4.  Everything worked like a charm up until then.  But when I took the leap to Csla4.0, things came to a full stop.  The DataPortal stopped functioning, completely.  My last note in that thread said that everything was fine, and it was.  I had discovered the last of my config errors and fixed it.

Unfortunately, as soon as I plugged in my login and a little bit of additional work that I have to in the Web project, I was exactly back at square one.  It was clear to me that something that I do in the Web project before going to SL page is causing the screw up.

Back in my test project where the Start Up Page was SilverlightTestPage.aspx (and every thing was working), I added a Default.aspx as the start up page where a button click sent me to SL page.  Everything was fine again.

I then added a standard Login page which uses my membership DB.  Again after login, everything was fine.

The Default page in my own project has a lot of code in the Page_Load event.  I copied that into the test project default page.  This code gets the logged in user's name from HttpContext and uses a standard class to get more information from the database.  By slowly commenting lines in Page_Load I now have the minimal code that will trip the apple cart.  And here it is:

protected void Page_Load(object sender, EventArgs e)
        {
            HttpRequest req = Request;
            WebUser mWebUser = WebUser.GetWebUser(HttpContext.Current.User.Identity.Name);
            //
        }

Web user is: 
          public class WebUser : Csla.BusinessBase<WebUser>

Here is the GetWebUser Factory method:
        public static WebUser GetWebUser(string userName)
        {
            return DataPortal.Fetch<WebUser>(new SingleCriteria<WebUser, string>(userName));
        }

And the DataPortal_Fetch method:
        public void DataPortal_Fetch(SingleCriteria<WebUser, string> criteria)
        {
            using (var ctx = ConnectionManager<SqlConnection>.GetManager("EnvMembershipConnectionString"))
            {
                using (var cm = ctx.Connection.CreateCommand())
                {
                    cm.CommandType = CommandType.StoredProcedure;
                    cm.CommandText = "UsersData_Select";
                    cm.Parameters.AddWithValue("@UName", criteria.Value);
                    using (var dr = new SafeDataReader(cm.ExecuteReader()))
                    {
                        FromDataReader(dr);
                        using (BypassPropertyChecks)
                        {
                            Status = "Retrieved";
                        }
                    }
                    BusinessRules.CheckRules();
                }
            }
        }

I have both the crossdomain.xml and the clientaccespolicy.xml files in the project, and the permission level of both will allow in everyone including the armed bandit.

I am sure there are other lines of code in the Default Page_Load which will do the same thing.  I don't see anything wrong  in any of this code .  All of this was working fine in VS10, .Net4.0, SL4.0 and Csla3.8.4  If I comment out those two lines in Page_Load, everything works fine - which means that I do not have configuration issues anymore (But I am also not implying that there is anything wrong with those two lines)

Jav

Jav replied on Monday, July 26, 2010

After posting that message, as I reflect on some common denomiator that causes the break, I think it has to be when I use the DataPortal from the Web project before going to SL page.

My 3.8.4 project also asks the user to select a person from a list of names which are obtained from the DB.  In the real  program that list is acquired using a BusinesBase<> object which returs a dataset (I know that is screwy way of doing things Big Smile).  But last evening when I used an SqlDataSource, there was NO error and everything worked fine.

I can zip up my test project and send it if that would make it easier.  Last time I tried uploading something, it didn't work.

Jav

Jav replied on Monday, July 26, 2010

Rocky,

I have a test project all zipped up, ready to send.  Unfortunately uploading a file from Options does not work (It has never worked for me).  I would be happy to email it if you think iy will be of help.  It would demonstrate what I am talking about in a flash.

Jav

RockfordLhotka replied on Monday, July 26, 2010

Does your web project have a reference to Csla.Web?

There is an issue with ApplicationContext when a project references Csla.Web and uses Silverlight - something I discovered when researching another problem - but I wonder if they are just different symptoms of the same thing.

Jav replied on Tuesday, July 27, 2010

No, the Web project only references Csla from the Server folder, as does the tiny demo project I created.  I have fiddled with this demo ad nauseam. By commenting or uncommenting a single line of code, I can make the error disappear or appear.

Jav

Jav replied on Tuesday, July 27, 2010

Interesting thing happened right after I posted the last note.  You may be on to something.  First I was looking in my little demo, and there was no Csla.Web. I also tested the demo, and it did give me the error.  So I answered your message. 

After that just to make sure that Csla reference was from Server folder, I clicked on the Csla reference, but I could not tell by looking in the Properties which folder it came from.  So I just went and refreshed the Csla reference from the Server folder.  Amazingly, I could not reproduce the error, the data was coming from the DataPortal everytime - regardless of whether my signal line of code was commented or uncommented.  Now just for kicks, I added the Csla.Web reference.  Lo and behold there was the erroneous behavior I had been seeing all day.  I removed the Csla.Web reference, and no error.  I added it back, and there was the error again. From this it would appear that this error can certainly occur with the inclusion of Cla.Web. But it is also possible that a Csla reference that is not from the right location can do that too. 

I have not tested it in my actual project, I have messed with that so much all day, I'll take me some time to put it back together before I can even start to test it. It will have to be tomorrow. 

Jav

RockfordLhotka replied on Tuesday, July 27, 2010

Well if you somehow had a Csla.Web.dll file in your web app's bin directory that would cause the issue I was seeing.

If that is your problem, the fix I'm going with for 4.0.1 is in svn now, and involves just one file:

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Source/Csla/ApplicationContext.cs?view=markup

 

Jav replied on Tuesday, July 27, 2010

That did it.  Thankyou, thankyou, thankyou.

I have only worked with my little demo, and I cannot make it fail.  I even added the Csla.Web in the Web project, and it still works.  It will take me a while before I will have my project running again, but I am confident it will work too.

Jav

Jav replied on Tuesday, July 27, 2010

YES.  Now it's my trusted ol' - working like a charm - Csla. Rolling up sleeves, diving into the BusinessRules.

Copyright (c) Marimer LLC