[mono-android] Being driven insane....
Andrew Sinclair
andrew at magic5software.com
Wed Feb 15 23:33:29 UTC 2012
This is an old thread but I stumbled across an answer (and solution) in case
anybody else ever has the problem...
Scenario:
- bug in app causes a crash and Android re-starts the app
- during the re-start the app de-serialises some stored data but this
fails, for example when de-serialising XmlElement. The same code works fine
most of the time.
It seems as though during the re-start some of the assemblies that are
usually "hanging around" (technical term) aren't there. So code like:
string typeName = "XmlElement";
Type type = GetType(typeName);
XmlSerializer s = new XmlSerializer(type);
would fail. Simply adding in the assembly name to help out the serialiser
will work:
string typeName = "XmlElement, System.Xml";
Hope this saves somebody some time one day!
Andy
-----Original Message-----
From: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Andrew Sinclair
Sent: 28 November 2011 15:36
To: 'Discussions related to Mono for Android'
Subject: Re: [mono-android] Being driven insane....
Paul,
Don't know if this helps...
When my app initialises it serialises/deserialises some simple data
(strings, ints etc).
If I deliberately put a bug into my application (because obviously there
aren't any real ones!) the app will crash with, say, a
NullReferenceException. Android then automatically re-starts the app and
that initialisation code always fails immediately with
System.ArgumentException relating to the serialisation that clearly works
fine the rest of the time. It's as though the re-start isn't totally clean
in some way and either Android or Mono for Android or the combination of
both get confused. This error itself causes a re-start and then everything
is fine (to the user this is seen as a double flicker of the screen.)
So... if I look in the adb log after an application error I'll usually see a
serialisation error. But if I look slightly earlier in the log I'll see the
*real* error that triggered this.
I've never looked into this much further because it's always been possible
to identify the underlying bug, it's just a bit strange that it has this
knock-on effect.
Maybe it's nothing to do with what you're seeing, but it's definitely a way
in which blatantly-obviously-this-serialisation-should-work fails to work.
Cheers,
Andy
-----Original Message-----
From: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of nodoid
Sent: 28 November 2011 14:01
To: monodroid at lists.ximian.com
Subject: Re: [mono-android] Being driven insane....
Hi,
Hmm, something is still not right. Are there any types which cannot be
serialized for Android?
Currently, I have this
[Serializable()]
public class common
{
public int p, a, w, pa;
public double bodyWeight, tempBody, tempSurround;
public double[,] correctionData = new double[3, 20];
public double[,] iterations = new double[3, 20];
public double c, b, cas;
public string s;
}
and to serialize in the main tab creator
[Activity(MainLauncher = true, Label = "@string/ApplicationName", Theme
= "@android:style/Theme.NoTitleBar")]
public class AndroidTimeOfDeath : TabActivity
{
protected override void OnCreate(Bundle bundle)
{
common data = new common();
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, typeof(TimeTemp));
intent.AddFlags(ActivityFlags.NewTask);
XmlSerializer x = new XmlSerializer(data.GetType());
StringWriter o = new
StringWriter(System.Globalization.CultureInfo.InvariantCulture);
x.Serialize(o, data);
// etc
}
The Serialize crashes and burns with a System.ArgumentException
I'm trying to figure out why this is happening and wonder if there are any
types that cannot be serialized. From a search, in standard C# Arrays of
ArrayList and certain generics can't be handled. Does Android add anything
additional to these?
I have changed the [Serializable] to [Serializable()] as well as commenting
it out and that makes no difference. The data.GetType() I have also tried as
typeof(common). Still crashes and burns.
Thanks
Paul
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/Being-driven-insane-tp5016975p
5028935.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid at lists.ximian.com
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
Monodroid at lists.ximian.com
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
More information about the Monodroid
mailing list