Hey guys: I'm getting a System.MissingMethodException: No parameterless constructor defined for this object error when trying to fetch objects in Silverlight.
I've read the other posts with similar titles, all of my BOs and criteria objects expose a public parameterless constructor in the Silverlight compiled assembly so I know it's not in my specific objects. Any idea where else this could be coming from?
Thanks, Will
The stack trace is:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader) in C:\Test Code\csla\cslacs\Csla\Serialization\Mobile\MobileFormatter.cs:line 259
at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream) in C:\Test Code\csla\cslacs\Csla\Serialization\Mobile\MobileFormatter.cs:line 208
at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data) in C:\Test Code\csla\cslacs\Csla\Serialization\Mobile\MobileFormatter.cs:line 356
at Csla.Server.Hosts.Silverlight.WcfPortal.GetCriteria(Byte[] criteriaData) in C:\Test Code\csla\cslacs\Csla\Server\Hosts\Silverlight\WcfPortal.cs:line 302
at Csla.Server.Hosts.Silverlight.WcfPortal.Fetch(CriteriaRequest request) in C:\Test Code\csla\cslacs\Csla\Server\Hosts\Silverlight\WcfPortal.cs:line 126
Ok, so this seems to work. I had put all of my public constructors inside of #if SILVERLIGHT blocks and left the normal private constructors in the #else block.
Removing the #if SILVERLIGHT and simply exposing a public parameterless constructor for all of my objects seems to have worked but I'm not sure why. Can someone explain this?
Thanks,
Will
The MobileFormatter requires a parameterless ctor. On the Silverlight side it must be public (due to reflection limitations) and on the .NET side it can be non-public - but either way it must be there.
In C# and VB, if you define a parameterized ctor the compiler won't automatically generate a parameterless ctor on your behalf. It sounds like you may have a paramterized ctor defined in your class, and on the .NET side that probably prevented the compiler from generating the parameterless ctor.
Copyright (c) Marimer LLC