[mono-android] Reflection - Cannot find default constructor

Andrew Sinclair andrew at magic5software.com
Fri Mar 25 09:13:40 EDT 2011


Willem,

 

This sounds like another variant of the "you need PreserveAttribute on your
constructor" that was mentioned earlier on today (see thread about
Activator.CreateInstance, excerpt from Jon's reply below)

 

Andy

-----

You're missing a [Android.Runtime.PreserveAttribute] on your constructor.

 

My apologies, as we need to better document this, but Mono for Android is
following the design of MonoTouch here:

 

      http://monotouch.net/Documentation/API_Design#PreserveAttribute

 

 

From: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Willem Meints
Sent: 25 March 2011 12:51
To: monodroid at lists.ximian.com
Subject: [mono-android] Reflection - Cannot find default constructor

 

Hi,

 

Before I start firing up a browser and send a bugreport about this it's
probably a good idea to check with you guys first. 

 

The problem I'm experiencing is that the Newton JSON library cannot find a
default constructor on a type I'm trying to deserialize. Since it works fine
on other platforms I thought that it might be a problem with MonoDroid
behaving incorrectly. So here's what I've tried:

 

Type type = typeof(IdentityProviderInformation);

ConstructorInfo constructor = type.GetConstructor(BindingFlags.Public |
BindingFlags.Instance,null,new Type[0], null);

 

if(constructor != null)

{

  Log.Info("MyApp","Constructor found");

}

 

The result is that the app doesn't find the constructor and doesn't print
the message into the log. The type has a default constructor, so it should
find it.

 

Can someone confirm this behavior?

 

Best regards,

 

Willem Meints

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110325/d4ea3376/attachment.html 


More information about the Monodroid mailing list