We develop apps for iOS and Android using xamarin.forms. In appcenter, it turns out that one of our apps sporadically crashes in iOS with an error: "System.IO.IOException: Too many open files".
We've been googling on what causes this issue. We checked all our code, and we made sure (as far as we can find) that all filestreams are properly closed and disposed after usage. We also found that the garbage collector of iOS can be too late in collecting the streams, so we added a manual GC.Collect() call in the methods using filestreams.
However, the issue still seems to appear. Is there a way we can monitor if any file handles are not being closed, so we can find out why this error still occurs?
Some info that might be relevant for troubleshooting suggestions:
- We're using Xamarin.Forms
- We're using Visual studio 2017 on Windows PC
- We have a mac connection in Visual studio to be able to build and debug the iOS version of our app
The full stacktrace of the crash:
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) <0x105032c20 + 0x005c8> in :0 System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean anonymous) <0x105032b70 + 0x0008f> in :0 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.IsolatedStorage.IsolatedStorageFile isf) <0x10503beb0 + 0x00057> in :0 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.IsolatedStorage.IsolatedStorageFile isf) <0x10503c000 + 0x00067> in :0 IsolatedStorageFile.OpenFile (System.String path, System.IO.FileMode mode) Deserializer+<>c.b__1_0 () Task1[TResult].InnerInvoke ()
Task.Execute ()
ExceptionDispatchInfo.Throw ()
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () Application+d__69.MoveNext ()