Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 2835 [details]
Project showing the problem
I have 2 binary files of the exact same size. I am using Assets.Open() to load them. When I call it on File A, it always loads. When I call it on File B, it always throws an exception. Whether I try to load File B first or last, it always fails. It throws a Java.IO.IOException with no message.
It is almost as if Assets.Open() is looking at the contents of the binary file and deciding it will not load it.
I have tested this on a Nexus 7 running Android 4.1.2, and a Droid Incredible running Android 2.3.4. Same problem on both.
I have attached a project that reproduces the issue.
Oddly, it works here on a Galaxy Nexus running Android 4.1.2.
I expect it to fail on Android <= 2.2 (iirc), because they don't support uncompressing files larger than 1MB. That's not the case on Android 2.3 or Android 4.1...
I could reproduce it with Nexus 7 (Android 4.1.2), MfA 4.2.8 beta on Mac. Output from slightly modified code to print full stack trace:
Forwarding debugger port 8893
Forwarding console port 8894
Detecting existing processLoaded assembly: /data/data/AndroidReadFileException.AndroidReadFileException/files/.__override__/AndroidReadFileException.dll
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: System.Core.dll [External]
Loaded assembly: MonoDroidConstructors [External]
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727
GREF GC Threshold: 46800
Error reading asset data
Unable to access asset data: -1
Java.IO.IOException: Exception of type 'Java.IO.IOException' was thrown.
at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue parms) [0x00024] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2-series/658a67dc/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:269
at Java.IO.InputStream.Read (System.Byte b, Int32 offset, Int32 length) [0x00045] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2-series/658a67dc/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Java.IO.InputStream.cs:249
at Android.Runtime.InputStreamInvoker.Read (System.Byte buffer, Int32 offset, Int32 count) [0x00000] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2-series/658a67dc/source/monodroid/src/Mono.Android/src/Runtime/InputStreamInvoker.cs:30
at System.IO.Stream.CopyTo (System.IO.Stream destination, Int32 bufferSize) [0x00000] in <filename unknown>:0
at System.IO.Stream.CopyTo (System.IO.Stream destination) [0x00000] in <filename unknown>:0
at AndroidReadFileException.Activity1.ReadFileToMemoryStream (System.String filename) [0x00013] in /Users/atsushi/Desktop/AndroidReadFileException/AndroidReadFileException/Activity1.cs:32
--- End of managed exception stack trace ---
at android.content.res.AssetManager.readAsset(Native Method)
at androidreadfileexception.Activity1.n_onCreate(Native Method)
at java.lang.reflect.Method.invokeNative(Native Method)
at dalvik.system.NativeStart.main(Native Method)
What jumps out at me:
> Unable to access asset data: -1
Web search suggests...not compressing the assets
That's not a very nice option, though it would work...
Regarding the two images I am loading: The broken one is a 1024x1024 image. The working one is a 2048x512 image.
Funny thing is I can workaround the problem by changing the size of my image.
Thanks for the article url. It seems like this may be the same or similar issue. He solved it with code, but mentioned that it could be solved with xml config files. I'll look around for the xml config option.
He mentioned that since the file was compressed, you couldn't read it that way. I wonder how you would read a file that is compressed.
Anyway, thanks for the help!
> I wonder how you would read a file that is compressed
On older Android platforms (with the aforementioned 1MB limit when decompressing assets), the answer is "you don't." Instead, you _store_ the file into the .apk uncompressed. You can specify which file extensions shouldn't be compressed in the Project Properties, e.g. in MonoDevelop's Project Options dialog, go to the Build > Mono for Android Build panel, and enter ".xnb" in the "Leave the following resource extensions uncompressed" textbox.
Wow, that is easy. :) Thanks for all the help.
Looks like if I target Android 2.3, there isn't a problem. I'll do that and add the .xnb extension to the "don't compress" list.
Thanks for the help!
I wonder if this is an upstream (aapt) bug or not and we should close this bug as such.
It's probably an upstream bug, but to verify that we'd have to write a Java app...