Problem when I upgrade from 3.6.1.0 to 3.6.2.0

Problem when I upgrade from 3.6.1.0 to 3.6.2.0

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


zhengokusa posted on Tuesday, May 19, 2009

I have a CLSA silverlight client/server project.

My custom Identity class throws exception if I use the new 3.6.2.0 dlls.

The private void DataPortal_Fetch(CredentialsCriteria criteria) never get called like in earlier version.

In my debuging output window I got

A first chance exception of type 'System.InvalidOperationException' occurred in Csla.DLL
A first chance exception of type 'System.TypeInitializationException' occurred in Csla.DLL
A first chance exception of type 'System.NullReferenceException' occurred in Csla.DLL
A first chance exception of type 'Csla.Server.DataPortalException' occurred in Csla.DLL
A first chance exception of type 'Csla.Server.DataPortalException' occurred in Csla.DLL
A first chance exception of type 'Csla.Server.DataPortalException' occurred in Csla.DLL
A first chance exception of type 'Csla.DataPortalException' occurred in Csla.DLL
A first chance exception of type 'Csla.DataPortalException' occurred in Csla.DLL

Is there something changed in CslaIdentity base class? How could I fix it?

Thanks,  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.Security;
using Csla.Core;
using Csla.Serialization;
using Csla.DataPortalClient;
using System.ComponentModel;

#if!SILVERLIGHT
using System.Data.SqlClient;
using Gears.Biz.Data;
#endif

using System.Diagnostics;
namespace Gears.Biz.Security
{
    [Serializable()]
    public class GearsIdentity:CslaIdentity
    {
        private static PropertyInfo<int> UserIdProperty = RegisterProperty<int>(new PropertyInfo<int>("UserId", "User Id", 0));
        public int UserId
        {
            get
            {
                return GetProperty<int>(UserIdProperty);
            }
        }
#if SILVERLIGHT
       
        public GearsIdentity(){}
        public static void GetIdentity(string username, string password, EventHandler<DataPortalResult<GearsIdentity>> completed)
        {
          GetCslaIdentity<GearsIdentity>(completed, new CredentialsCriteria(username, password));
        }     
#else
        public static void GetIdentity(string username, string password, string roles)
        {
            GetCslaIdentity<GearsIdentity>(new CredentialsCriteria(username, password));
        }
       
        private void DataPortal_Fetch(CredentialsCriteria criteria)
        {
            using (SqlConnection connection = new SqlConnection(DataConnection.ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("sp_GetUser", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@user", criteria.Username));
                    using (Csla.Data.SafeDataReader reader = new Csla.Data.SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            if (criteria.Password == reader.GetString("Password") && reader.GetString("Password") != string.Empty)
                            {
                                LoadProperty<int>(UserIdProperty, reader.GetInt32("UserId"));
                               
                                Name = reader.GetString("UserName");
                               
                                Roles = new MobileList<string>(new string[] { reader.GetString("Role") });
                               
                                IsAuthenticated = true;                            
                            }
                        }
                    }
                }
                connection.Close();
            }
        }
#endif
    }
}

sergeyb replied on Tuesday, May 19, 2009

I think you need to add type for register property for user id.  I believe this is something that was fixed in CSLA .3.6.2 – it will throw an exception unless you specify the type.  It is probably throwing this exception, you are just not seeing it.

 

static PropertyInfo<int> UserIdProperty = RegisterProperty<int>(new PropertyInfo<int>(typeof(GearsIdentity),"UserId", "User Id", 0));

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: zhengokusa [mailto:cslanet@lhotka.net]
Sent: Tuesday, May 19, 2009 5:32 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Problem when I upgrade from 3.6.1.0 to 3.6.2.0

 

I have a CLSA silverlight client/server project.

My custom Identity class throws exception if I use the new 3.6.2.0 dlls.

The private void DataPortal_Fetch(CredentialsCriteria criteria) never get called like in earlier version.

Is there something changed in CslaIdentity base class? How could I fix it?

Thanks,  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.Security;
using Csla.Core;
using Csla.Serialization;
using Csla.DataPortalClient;
using System.ComponentModel;

#if!SILVERLIGHT
using System.Data.SqlClient;
using Gears.Biz.Data;
#endif

using System.Diagnostics;
namespace Gears.Biz.Security
{
    [Serializable()]
    public class GearsIdentity:CslaIdentity
    {
        private static PropertyInfo<int> UserIdProperty = RegisterProperty<int>(new PropertyInfo<int>("UserId", "User Id", 0));
        public int UserId
        {
            get
            {
                return GetProperty<int>(UserIdProperty);
            }
        }
#if SILVERLIGHT
       
    &nb sp;   public GearsIdentity(){}
        public static void GetIdentity(string username, string password, EventHandler<DataPortalResult<GearsIdentity>> completed)
        {
          GetCslaIdentity<GearsIdentity>(completed, new CredentialsCriteria(username, password));
        }     
#else
        public static void GetIdentity(string username, string password, string roles)
        {
            GetCslaIdentity<GearsIdentity>(new CredentialsCriteria(username, password));
        }
       
        private void DataPortal_Fetch(CredentialsCriteria criteria)
        {
            using (SqlConnection connection = new SqlConnection(DataConnection.ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("sp_GetUser", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                  & nbsp; command.Parameters.Add(new SqlParameter("@user", criteria.Username));
                    using (Csla.Data.SafeDataReader reader = new Csla.Data.SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            if (criteria.Password == reader.GetString("Password") && reader.GetString("Password") != string.Empt y)
                            {
                                LoadProperty<int>(UserIdProperty, reader.GetInt32("UserId"));
                               
                                Name = reader.GetString("UserName");
                       & nbsp;       
                                Roles = new MobileList<string>(new string[] { reader.GetString("Role") });
                               
                                IsAuthenticated = true;                            
               &n bsp;            }
                        }
                    }
                }
                connection.Close();
            }
        }
#endif
    }
}



zhengokusa replied on Wednesday, May 20, 2009

What I can say! This morning I first came to office, and opened up my outlook. There was Sergey's response email, and IT WAS THE SOLUTION.

This is the summary of what have happened to me since I upgrade from 3.6.1.0 to 3.6.2.0. Just in case other people may running into the same problem. 

In your custom identity class, if you have a custom property, you have to declare thenm as following

private static PropertyInfo<int> UserIdProperty = RegisterProperty<int>(typeof(GearsIdentity), new PropertyInfo<int>("UserId", "User Id"));
        public int UserId
        {
            get
            {
                return GetProperty<int>(UserIdProperty);
            }
        }

The "typeof(GearsIdentity)" is required parameter right now.

Since the rest of my biz classes are still working, so I just assume that they don't require that syntax to

be in every custom property in your biz classes. Well, there might be something I have not discovered. I welcome any comments.

Again Thanks

 

 

 

 

 

 

Copyright (c) Marimer LLC