Bug 1529 - Exception in System.Array.Copy
Summary: Exception in System.Array.Copy
Status: RESOLVED DUPLICATE of bug 3676
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-10-17 07:13 UTC by Matt Jones
Modified: 2012-04-09 18:36 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Matt Jones 2011-10-17 07:13:16 UTC
Since updating to MonoTouch 5.0 I get regular exceptions in System.Array.Copy when called from a particular line of my code. I can stop it doing it in about 9 of 10 cases by quitting the iPhone Simulator after my debugging session stops.

My line of code is:

object[] attributes=f.GetCustomAttributes(typeof(XmlMapAttribute),false);

My exception is:

Object reference not set to an instance of an object

And this is the stack trace:

  at System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) [0x00104] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Array.cs:979 
  at System.Collections.ArrayList.CopyTo (Int32 index, System.Array array, Int32 arrayIndex, Int32 count) [0x0002d] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections/ArrayList.cs:3064 
  at System.Collections.ArrayList.CopyTo (System.Array array, Int32 arrayIndex) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections/ArrayList.cs:3046 
  at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x0026c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/MonoCustomAttrs.cs:259 
  at System.Reflection.MonoField.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoField.cs:101 
  at SaturnTrader.ClientCore.Utils.XMLUtils.ReadXml (System.Xml.XmlNode e, System.Object o, SaturnTrader.ClientCore.Utils.SetValueDelegate setter) [0x0003a] in /Users/spreadcomattjones/Projects/iPadTest1/Comms/Utils/XMLUtils.cs:286
Comment 1 Matt Jones 2011-10-17 11:48:16 UTC
In addition I have had the following exception just once:

System.InvalidOperationException: The vm is not suspended.
at Mono.Debugger.Soft.VirtualMachine.ErrorHandler (System.Object sender, Mono.Debugger.Soft.ErrorHandlerEventArgs args) [0x0004d] in /private/tmp/source/monodevelop/main/contrib/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs:252 
at Mono.Debugger.Soft.Connection.SendReceive (CommandSet command_set, Int32 command, Mono.Debugger.Soft.PacketWriter packet) [0x000ac] in /private/tmp/source/monodevelop/main/contrib/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs:1255 
at Mono.Debugger.Soft.Connection.Thread_GetFrameInfo (Int64 id, Int32 start_frame, Int32 length) [0x00000] in /private/tmp/source/monodevelop/main/contrib/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs:1578 
at Mono.Debugger.Soft.ThreadMirror.GetFrames () [0x00000] in /private/tmp/source/monodevelop/main/contrib/Mono.Debugger.Soft/Mono.Debugger.Soft/ThreadMirror.cs:15 
at Mono.Debugging.Soft.SoftDebuggerBacktrace..ctor (Mono.Debugging.Soft.SoftDebuggerSession session, Mono.Debugger.Soft.ThreadMirror thread) [0x0002c] in /private/tmp/source/monodevelop/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerBacktrace.cs:50 
at (wrapper remoting-invoke-with-check) Mono.Debugging.Soft.SoftDebuggerBacktrace:.ctor (Mono.Debugging.Soft.SoftDebuggerSession,Mono.Debugger.Soft.ThreadMirror)
at Mono.Debugging.Soft.SoftDebuggerSession.GetThreadBacktrace (Mono.Debugger.Soft.ThreadMirror thread) [0x00000] in /private/tmp/source/monodevelop/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs:606 
at Mono.Debugging.Soft.SoftDebuggerSession.OnGetThreadBacktrace (Int64 processId, Int64 threadId) [0x00000] in /private/tmp/source/monodevelop/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs:601 
at Mono.Debugging.Client.DebuggerSession.GetBacktrace (Int64 processId, Int64 threadId) [0x00011] in /private/tmp/source/monodevelop/main/src/core/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs:936 
at Mono.Debugging.Client.ThreadInfo.get_Backtrace () [0x0000b] in /private/tmp/source/monodevelop/main/src/core/Mono.Debugging/Mono.Debugging.Client/ThreadInfo.cs:79 
at Mono.Debugging.Client.ThreadInfo.get_Location () [0x0000b] in /private/tmp/source/monodevelop/main/src/core/Mono.Debugging/Mono.Debugging.Client/ThreadInfo.cs:64 
at MonoDevelop.Debugger.ThreadsPad.AppendThreads (TreeIter it, Mono.Debugging.Client.ProcessInfo p) [0x00091] in /private/tmp/source/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ThreadsPad.cs:174 
at MonoDevelop.Debugger.ThreadsPad.UpdateDisplay () [0x00035] in /private/tmp/source/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ThreadsPad.cs:146
Comment 2 Rolf Bjarne Kvinge [MSFT] 2011-10-17 16:39:35 UTC
Looking at the source code the exception doesn't make much sense - so it might be something strange that's going on. Can you create a reproducible test case we can look at? That would make it a lot faster and easier to fix.
Comment 3 Matt Jones 2011-10-18 06:18:32 UTC
Thanks for your response. I will see if I can reproduce it in a small test case, but I'm doubtful if I can.
Comment 4 Sebastien Pouliot 2011-10-19 08:31:33 UTC
If you can't provide a smaller test case that shows the issue could you give us:

a) the definition of XmlMapAttribute (it's not in the FX afaik)
b) how it is used on the fields (e.g. parameters)
c) the linker settings you're using

Comment 5 Matt Jones 2011-10-20 06:25:44 UTC
	public class XmlMapAttribute : Attribute
		public string Element;
		public string Attribute;
		public bool List;

	public class Accounts
		EServiceSelection service;
		public List<Account> list=new List<Account>();
		public int Count { get { return list.Count; } }
		public string status;
		public string mno;
		public string mof;
		public string rows;
		public Accounts(EServiceSelection _service)
		public void Load(XmlElement msg)
				foreach(XmlElement e in msg.FirstChild.ChildNodes)
					Account acc=new Account();
					// these should be <Account> elements
					Debug.WriteLine("Reading account "+acc.DisplayName+" type "+acc.pm.ToString());
			catch(Exception ex)
				Debug.WriteLine("Exception: "+ex.ToString());


As to linker options, it's set not to link as this is happening in the simulator.
Comment 6 Sebastien Pouliot 2011-10-20 08:30:23 UTC
Thanks, but it does not really answer 'b' (the [XmlMapAttribute] is not used, only [Ignore]) and I'd like you to confirm (c) since it's the simulator defaut but it *can* be changed using MonoDevelop (or by specifying additional arguments to mtouch).
Comment 7 Matt Jones 2011-10-20 08:39:09 UTC
(b) this - Accounts - is the class that is blowing it up and there is no use of XmlMap on that particular class.

Here is how I use that attribute on other classes, typically:

... in the middle of a class:

		public decimal spic;
		public decimal ptfctr;
		public EChargingType chargingType;
		public decimal pipsize;

(c) I can confirm that it's set to not link and there are no additional mtouch arguments.
Comment 8 Sebastien Pouliot 2011-10-25 11:44:08 UTC
Beside a threading issue it's difficult to see how this could occurs. FWIW there are other reports that hints to some changes in iOS5 (i.e. things that worked before, on iOS4.3, on separate threads) are now having issues.

Sadly we'll need a test case or the application* itself to further debug this issue. 

* You can email support@xamarin.com for the NDA paperworks (if needed).
Comment 9 Sebastien Pouliot 2012-04-09 18:36:10 UTC
another bug report provided a test case (same stack trace) and was fixed recently

*** This bug has been marked as a duplicate of bug 3676 ***