The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Serialization Problems with RC ?

Last post 06-27-2008, 3:39 PM by Mike.Griffin. 11 replies.
Sort Posts: Previous Next
  •  06-17-2008, 11:07 AM 9851

    Serialization Problems with RC ?

    I have just updated  to the RC version and am now having problems I haven't had previously.  For smaller tables (lookup, etc), I sometimes place a collection in Session/ViewState.  This has not been a problem until today.  I don't receive any messages when placing the collection in state or when retrieving it.  However, when I try to access properties I get a null reference error.  I am performing a .FindByPrimaryKey to load a single object from state (no errors) and the (an) object is returned seemingly intact until a try to read a value from one of the field/column properties.

    Have you noticed this behavior?  It did not exist previously.  I could change techniques easily enough, but this should work unless ES 2008 objects are no longer serilizable (and I know that's not the case).

     


    Thanks
    Mark
  •  06-17-2008, 12:54 PM 9858 in reply to 9851

    Re: Serialization Problems with RC ?

    We shouldn't have broken this, can you post some code samples for us, we need to fix this. Use the Code Button when posting the code, it makes it easy to read. It passes all of our serialization unit tests however. You did regenerate your classes right?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-18-2008, 6:09 AM 9866 in reply to 9858

    Re: Serialization Problems with RC ?

    Ok, Mike.  Here is the pertinent code.  It is a web application in C# 3.5

    The form, at it's core, is a simple one.  Display a list, user selects item, display details.  The Form's Load event calls the method to load the list:

    Code:
            /// <summary>
            /// Loads the groups into the list
            /// This refreshes from the database
            /// </summary>
            private void LoadGroups()
            {
                try
                {
                    // Forces a refresh from the database
                    ViewState.Remove(GROUPS);
                    lstSecurityGroup.DataSource = Groups;
                    lstSecurityGroup.DataTextField = "Name";
                    lstSecurityGroup.DataValueField = "SecurityGroupId";
                    lstSecurityGroup.DataBind();
                    if (lstSecurityGroup.Items.Count > 0)
                    {
                        lstSecurityGroup.SelectedIndex = 0;
                        lstSecurityGroup_SelectedIndexChanged(null, null);       // Display the details for the first item
                    }
    
                    // Setup for group copy
                    cboGroupCopy.Items.Clear();
                    cboGroupCopy.Items.Add(new ListItem(String.Empty, "0"));
                    foreach (ListItem item in lstSecurityGroup.Items)
                    {
                        cboGroupCopy.Items.Add(new ListItem(item.Text, item.Value));
                    }
    
                }
                catch (Exception ex)
                {
                    LogError(ex);
                }
            }
    

    The DataSource for the list is a form property.  The property checks ViewState for an existing collection and, if missing, loads it from the DB.

    Code:
            /// <summary>
            /// Returns the group collection.
            /// A call is made to the database only if the 
            /// ViewState is empty
            /// </summary>
            private SecurityGroupCollection Groups
            {
                get
                {
                    if (ViewState[GROUPS] == null)
                    {
                        try
                        {
                            SecurityGroupCollection sGroups = new SecurityGroupCollection();
                            sGroups.Query.OrderBy(sGroups.Query.Name, esOrderByDirection.Ascending);
                            sGroups.Query.Load();
                            ViewState.Add(GROUPS, sGroups);
                        }
                        catch (Exception ex)
                        {
                            LogError(ex);
                        }
                    }
                    return (SecurityGroupCollection)ViewState[GROUPS];
                }
            }
    

    When the user selects a new item in the list, the SelectedIndexChanged event displays it to the form.  Inside that event is a call to this method.

    Code:
            /// <summary>
            /// Fill the group info tab with information
            /// </summary>
            private void SetGroupInfo()
            {
                try
                {
                    txtGroupName.Text = SelectedGroup.str.Name;
                    txtGroupDescription.Text = SelectedGroup.Description;
                    cboGroupCopy.SelectedIndex = 0;
                    CreatingGroup = false;
                }
                catch (Exception ex)
                {
                    LogError(ex);
                }
            }
    

    This method fails on the call to SelectedGroup.str.Name.  I added the .str property in an attempted to find the cause of this problem.  Name is already a string property so .str is not necessary.  Here is the SelectedGroup property.

    Code:
            /// <summary>
            /// Returns the SecurityGroup selected in the list
            /// </summary>
            private SecurityGroup SelectedGroup
            {
                get
                {
                    SecurityGroup retGroup = new SecurityGroup();
                    try
                    {
                        retGroup = Groups.FindByPrimaryKey(Convert.ToInt32(lstSecurityGroup.SelectedValue));
                    }
                    catch (Exception ex)
                    {
                        LogError(ex);
                    }
                    return retGroup;
                }
            }
    

    This property always runs successfully.  A SecurityGroup object is always returned.  Although all of it's DB field properties fail when called.  Oddly enough, this only happens after the initial load of the page.  The first call (in the form load event) works fine.  Here is the error from the log.

    Code:
    Page:  Admin/GroupAdmin.aspx  
    Exception Data:  System.Collections.ListDictionaryInternal  
    Event:  System.String GetSystemString(System.String)  
    Message:  Object reference not set to an instance of an object.  
    Stack Trace:  at EntitySpaces.Core.esEntity.GetSystemString(String columnName) at 
    BusinessObjects.esSecurityGroup.get_Name() in 
    D:\Documents and Settings\Mark\My Documents\Visual Studio 2008\Projects\DTAWeb2\DTAWeb2\Generated\SecurityGroup.cs:line 238 
    at BusinessObjects.esSecurityGroup.esStrings.get_Name() in 
    D:\Documents and Settings\Mark\My Documents\Visual Studio 2008\Projects\DTAWeb2\DTAWeb2\Generated\SecurityGroup.cs:line 340 
    at DTAWeb2.Admin.GroupAdmin.SetGroupInfo() in D:\Documents and Settings\Mark\My Documents\Visual Studio 2008\Projects\DTAWeb2\DTAWeb2\Admin\GroupAdmin.aspx.cs:line 402  
    

    Line 238 of the generated code is the Get.

    Code:
    		/// <summary>
    		/// Maps to SECURITY_GROUP.Name
    		/// </summary>
    		virtual public System.String Name
    		{
    			get
    			{
    				return base.GetSystemString(SecurityGroupMetadata.ColumnNames.Name);
    			}
    			
    			set
    			{
    				if(base.SetSystemString(SecurityGroupMetadata.ColumnNames.Name, value))
    				{
    					this.MarkFieldAsModified(SecurityGroupMetadata.ColumnNames.Name);
    				}
    			}
    		}
    

    Line 340 is the first line of this Get.

    Code:
    			public System.String Name
    			{
    				get
    				{
    					System.String data = entity.Name;
    					return (data == null) ? String.Empty : Convert.ToString(data);
    				}
    
    				set
    				{
    					if (value == null || value.Length == 0) entity.Name = null;
    					else entity.Name = Convert.ToString(value);
    				}
    			}
    
     

    I do not have the ES source code, so stepping beyond "base.GetSystemString(SecurityGroupMetadata.ColumnNames.Name);" is not possible for me.

    Yes, I did regenerate my classes. I was forced to because of some "OnLoad" event that was no longer valid inside all the classes. I'm sorry, I don't remember the exact delegate name that was being setup. I could probably find out if you really need to know.

    Were MyGeneration templates updated? It seems wierd to me that regenerating did not create the same line. I don't remember updating my templates for ES 2008. That is to say, I already had templates for ES 2008 and did not update them when I downloaded the RC.


    Thanks
    Mark
  •  06-19-2008, 4:27 AM 9885 in reply to 9858

    Re: Serialization Problems with RC ?

    Is there an issue?  Should I change my technique?  It's not like you guys to leave a topic unattended for this long...
    Thanks
    Mark
  •  06-19-2008, 4:35 AM 9886 in reply to 9885

    Re: Serialization Problems with RC ?

    We talked about this very post in our status meeting last night. Scott will be reproducing this today. It is very important that this work for ES2008, so we will be gettnig back to you today.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-19-2008, 4:42 AM 9889 in reply to 9886

    Re: Serialization Problems with RC ?

    Thanks, Mike.  Honestly, I hope it works for you and the problem is on my end (with templates or something).
    Thanks
    Mark
  •  06-19-2008, 7:46 AM 9890 in reply to 9889

    Re: Serialization Problems with RC ?

    **Update, I was able to replicate the Null Reference. We will take a look at what is going on...

     



    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  06-19-2008, 8:42 AM 9894 in reply to 9890

    Re: Serialization Problems with RC ?

    We tracked down this issue, it was actually in the enumeration after de-serialization. We will have this corrected in the ES2008 RTM. Thank you for helping us track this down, this is exactly why we do betas, then rc's.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  06-19-2008, 2:00 PM 9901 in reply to 9894

    Re: Serialization Problems with RC ?

    Glad I could help.  More glad that the fix isn't all that difficult to implement.  You guys all do great work!  I've built libraries like this before.  Except I didn't have to support so many different platforms and databases.  So I deeply appreciate the effort...

     I look forward to the RTM.


    Thanks
    Mark
  •  06-19-2008, 6:58 PM 9904 in reply to 9901

    Re: Serialization Problems with RC ?

    The fix was just rolled in ...

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-27-2008, 3:32 PM 10040 in reply to 9904

    Re: Serialization Problems with RC ?

    Sweet!  Everything works again.

     Great Job!


    Thanks
    Mark
  •  06-27-2008, 3:39 PM 10042 in reply to 10040

    Re: Serialization Problems with RC ?

    Excellent, and you saved our butts when you posted that error, we caught it before the release, so thanx !! Big Smile

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML