No Parameterless Constructors in Silverlight

No Parameterless Constructors in Silverlight

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


st3fanus posted on Thursday, July 19, 2012

Hi all

I have three days in looking for a solution for this problem in my development

I develop Silverlight 5 app, I used CSLA 4.3.12

 

I Got : No Parameterless constructors defined for this object

Jonny has suggest me to add public default constructor in ALL my business object

in this problem i have MenuList : ReadOnlyListBase<MenuList, MenuInfo>

AND I have add :

public MenuList()

{
}

in MenuList Class

public MenuInfo()

{
}

in MenuInfo

BUT I still got the same error when i display that error.

 

Could anyone know what is happened here ?

Could you help me to save my days :(

 

 

thanks a lot

 

Stefanus

 

skagen00 replied on Thursday, July 19, 2012

Are you using a criteria class to fetch the objects? Don't forget the public constructor on the criteria class if that's the case.

st3fanus replied on Thursday, July 19, 2012

Hi skagen.. thanks for your quick response

 

No I'm not use criteria class, i just use string plain type

 

But I use my Dal not follow lhotka book use Provider pattern, BUT I use Mef to load my dal implementation

 

Could you have another suggestions ?

 

thanks a lot

 

stefanus

st3fanus replied on Thursday, July 19, 2012

Wow Incredible

 

I don't know what wrong is it ?

I have make my ALL BUSINESS OBJECT has public default constructor parameterless

 

BUT it is still got NO Parameterless Constructors defined in this object ??????

 

 

 

st3fanus replied on Thursday, July 19, 2012

namespace AIS.Lib.Menu
{
    [Serializable]
    public class MenuList : ReadOnlyListBase<MenuList, MenuInfo>
    {
        public MenuList()
        {

        }

        public static void GetMenuList(string username,
            EventHandler<DataPortalResult<MenuList>> callback)
        {
            var criteria = new MenuCriteria(username);
            DataPortal.BeginFetch<MenuList>(criteria, callback);
        }

#if !SILVERLIGHT

        private void DataPortal_Fetch(MenuCriteria criteria)
        {

        }
#endif
    } // end of class
}

 

 

namespace AIS.Lib.Menu
{
    [Serializable]
    public class MenuInfo : ReadOnlyBase<MenuInfo>
    {
        public MenuInfo()
        {

        }

        public static readonly PropertyInfo<int> ClassIdProperty =
            RegisterProperty<int>(t => t.ClassId);
        public int ClassId
        {
            get { return GetProperty(ClassIdProperty); }
            private set { LoadProperty(ClassIdProperty, value); }
        }

        public static readonly PropertyInfo<string> ClassNameProperty =
            RegisterProperty<string>(t => t.ClassName);
        public string ClassName
        {
            get { return GetProperty(ClassNameProperty); }
            private set { LoadProperty(ClassNameProperty, value); }
        }

#if !SILVERLIGHT

        private void Child_Fetch(System.Data.IDataReader data)
        {
            ClassId = data.GetInt32(data.GetOrdinal("ClassId"));
            ClassName = data.GetString(data.GetOrdinal("ClassName"));
        }

#endif
    } // end of class
}

 

What do i miss in this code ??

 

thanks a lot

stefanus

RockfordLhotka replied on Thursday, July 19, 2012

What we do know is that some object that is being serialized by the data portal does not have a public default constructor.

Clearly we don't know what object is missing that constructor. So a process of elimination is required.

  1. The data portal will serialize your object graph. That includes your root, parent, and child objects that make up the object graph. (It will also serialize any objects referenced by objects in your object graph, if those references are held in managed properties)
  2. It will also serialize your principal and identity objects.
  3. It will also serialize any objects in ApplicationContext.ClientContext and ApplicationContext.GlobalContext.
  4. It will also serialize any criteria object you pass to BeginCreate, BeginFetch, or BeginDelete.

 I would recommend building a small test app that avoids using as many of these types of object as possible. Start small, and keep adding more complexity until you discover the type of object you've implemented that is missing a public default constructor.

RockfordLhotka replied on Thursday, July 19, 2012

Another way to help isolate the problem is to use the Clone method on your root object.

The Clone method (on Silverlight) will use the MobileFormatter to serialize and deserialize the object graph. But it won't try to serialize principal, identity, criteria, or context objects. It will only serialize the object graph. That should help limit the scope of the serialization so you can easily find out if the issue is in the business object graph or somewhere else.

Copyright (c) Marimer LLC