Bug 1054 - Loading XML from Assets : System.Xml.XmlException: Invalid data ---> System.ArgumentOutOfRangeException: ArgRange_Array
Summary: Loading XML from Assets : System.Xml.XmlException: Invalid data ---> System.A...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 1.0
Hardware: PC Windows
: High major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-26 11:39 UTC by Philippe Girolami
Modified: 2011-09-27 15:08 UTC (History)
3 users (show)

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


Attachments
Project to reproduce exception (827.52 KB, application/x-zip-compressed)
2011-09-26 11:39 UTC, Philippe Girolami
Details


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:
Status:
RESOLVED FIXED

Description Philippe Girolami 2011-09-26 11:39:07 UTC
Created attachment 494 [details]
Project to reproduce exception

Similar to https://bugzilla.novell.com/show_bug.cgi?id=696088, I am unable to get this to work:

            XmlDocument xmlDocument = new XmlDocument();
            Stream fileStream = Assets.Open("TextFile1.xml");
            xmlDocument.Load(fileStream);

Attached is a project to reproduce the error

Stack trace follows
I/MonoDroid(24060): UNHANDLED EXCEPTION: System.Xml.XmlException: Invalid data ---> System.ArgumentOutOfRangeException: ArgRange_Array
I/MonoDroid(24060): Parameter name: byteCount
I/MonoDroid(24060):   at System.Text.UTF8Encoding.InternalGetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00059] in /home/jon/Development/xamarin/mono/mcs/class/corlib/System.Text/UTF8Encoding.cs:664 
I/MonoDroid(24060):   at System.Text.UTF8Encoding+UTF8Decoder.GetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex) [0x00004] in /home/jon/Development/xamarin/mono/mcs/class/corlib/System.Text/UTF8Encoding.cs:950 
I/MonoDroid(24060):   at System.Xml.NonBlockingStreamReader.ReadBuffer () [0x00042] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlInputStream.cs:193 
I/MonoDroid(24060):   at System.Xml.NonBlockingStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00072] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlInputStream.cs:237 
I/MonoDroid(24060):   at System.Xml.XmlStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlInputStream.cs:64 
I/MonoDroid(24060):   --- End of inner exception stack trace ---
I/MonoDroid(24060): at System.Xml.XmlStreamReader.Read (char[],int,int) [0x00010] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlInputStream.cs:68
I/MonoDroid(24060): at Mono.Xml2.XmlTextReader.ReadTextReader (int) [0x0013a] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1278
I/MonoDroid(24060): at Mono.Xml2.XmlTextReader.PeekChar () [0x00047] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1203
I/MonoDroid(24060): at Mono.Xml2.XmlTextReader.ReadContent () [0x0003f] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1297
I/MonoDroid(24060): at Mono.Xml2.XmlTextReader.Read () [0x00141] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlTextReader.cs:620
I/MonoDroid(24060): at System.Xml.XmlTextReader.Read () [0x0006b] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlTextReader2.cs:564
I/MonoDroid(24060): at Mono.Xml.EntityResolvingXmlReader.Read () [0x0009b] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/EntityResolvingXmlReader.cs:393
I/MonoDroid(24060): at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00027] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs:1585
I/MonoDroid(24060): at System.Xml.XmlValidatingReader.Read () [0x00104] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlValidatingReader.cs:507
I/MonoDroid(24060): at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader) [0x00363] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlDocument.cs:1021
I/MonoDroid(24060): at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader) [0x00047] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlDocument.cs:874
I/MonoDroid(24060): at System.Xml.XmlDocument.Load (System.Xml.XmlReader) [0x00019] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlDocument.cs:738
I/MonoDroid(24060): at System.Xml.XmlDocument.Load (System.IO.Stream) [0x0002e] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlDocument.cs:696
I/MonoDroid(24060): at Bug1.Activity1.OnCreate (Android.OS.Bundle) [0x0002d] in d:\TFS\Android\Bug1\Activity1.cs:25
I/MonoDroid(24060): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /home/jpobst/Desktop/monodroid/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1441
I/MonoDroid(24060): at (wrapper dynamic-method) object.f80f05f2-c1d8-4a4c-9d8f-47ac63e28756 (intptr,intptr,intptr) <IL 0x00012, 0x00033>
V/AlarmManager(  130): --- from triggerAlarmsLocked operation: com.acer.android.widget.digitalclock
I/AlarmManager(  130): ----Alarm type: 1Second:1317051900.0
I/AlarmManager(  130): Alarm type : 1, from setRepeating operation : android
I/AlarmManager(  130): ----Alarm type: 1Second:1317051300.0
E/mono    (24060): 
E/mono    (24060): Unhandled Exception: System.Xml.XmlException: Invalid data ---> System.ArgumentOutOfRangeException: ArgRange_Array
E/mono    (24060): Parameter name: byteCount
E/mono    (24060):   at System.Text.UTF8Encoding.InternalGetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00059] in /home/jon/Development/xamarin/mono/mcs/class/corlib/System.Text/UTF8Encoding.cs:664 
E/mono    (24060):   at System.Text.UTF8Encoding+UTF8Decoder.GetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex) [0x00004] in /home/jon/Development/xamarin/mono/mcs/class/corlib/System.Text/UTF8Encoding.cs:950 
E/mono    (24060):   at System.Xml.NonBlockingStreamReader.ReadBuffer () [0x00042] in /home/jon/Development/xamarin/mono/mcs/class/System.XML/System.Xml/XmlInputStream.cs:193 
E/mono    (24060):   at System.Xml.NonBlockingStreamReader.Read (System.Char[] dest_bu
D/Zygote  (   82): Process 24060 exited cleanly (1)
I/ActivityManager(  130): Process Bug1.Bug1 (pid 24060) has died.
Comment 1 Jonathan Pobst 2011-09-26 12:54:40 UTC
Here is a workaround until this bug is fixed:

using (var fileStream = Assets.Open ("TextFile1.xml"))
    using (var reader = new StreamReader (fileStream)) {
	var content = reader.ReadToEnd ();
	xmlDocument.LoadXml (content);
}
Comment 2 Philippe Girolami 2011-09-27 04:21:42 UTC
Workaround works. Thanks for the quick turnaround.
Comment 3 Rodrigo Kumpera 2011-09-27 15:08:06 UTC
Fixed on mono for android master. The fix will be in 1.9.1 or 2.0 (not sure the numbering of the next release).

Thanks for the test case.