Bug 36233 - FileStream with FileOptions.Asynchronous throws exception when reading
Summary: FileStream with FileOptions.Asynchronous throws exception when reading
Status: NEEDINFO
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-25 00:57 UTC by Jiri {x2} Cincura
Modified: 2017-10-11 17:24 UTC (History)
6 users (show)

Tags:
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 for Bug 36233 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description Jiri {x2} Cincura 2015-11-25 00:57:32 UTC
Creating a `FileStream` like:
new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Write | FileShare.Delete, Global.LocalFileBufferSize, FileOptions.Asynchronous | FileOptions.SequentialScan);

and then reading (or `ReadAsync`, fails the same way):
result.Read(buffer, 0, buffer.Length);

throws exception:
System.IO.IOException: Invalid parameter
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end
_invoke (object,intptr)
  at (wrapper delegate-end-invoke) <Module>:end_invoke_int__this___IAsyncResult
(System.IAsyncResult)
  at System.IO.FileStream.EndRead (IAsyncResult asyncResult) [0x00063] in C:\j\w
orkspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.cs:605
  at System.IO.FileStream.Read (System.Byte[] array, Int32 offset, Int32 count)
[0x000b1] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.c
s:523

Removing the FileOptions.Asynchronous solves the problem.
Comment 1 Marek Safar 2015-11-26 10:57:29 UTC
I cannot reproduce the issue. Based on your description following repro works as expected.

using System;
using System.IO;

class MainClass
{
	public static void Main (string[] args)
	{
		var buffer = new byte[1024];
		var fs = new FileStream("Console57.exe", FileMode.Open, FileAccess.Read, FileShare.Read |
			FileShare.Write | FileShare.Delete, buffer.Length,
			FileOptions.Asynchronous | FileOptions.SequentialScan);

		var l = fs.Read(buffer, 0, buffer.Length);
	}
}
Comment 2 Jiri {x2} Cincura 2015-11-27 01:08:38 UTC
This is exactly the code I use now:

using System.IO;
using System.Reflection;

class MainClass
{
    public static void Main(string[] args)
    {
        var buffer = new byte[1024];
        var fs = new FileStream(Assembly.GetExecutingAssembly().Location, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Write | FileShare.Delete, buffer.Length, FileOptions.Asynchronous | FileOptions.SequentialScan);
        var l = fs.Read(buffer, 0, buffer.Length);
    }
}

Then:
> mcs Program.cs
> mono --debug Program.exe

Results in:

Unhandled Exception:
System.IO.IOException: Invalid parameter
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end
_invoke (object,intptr)
  at (wrapper delegate-end-invoke) <Module>:end_invoke_int__this___IAsyncResult
(System.IAsyncResult)
  at System.IO.FileStream.EndRead (IAsyncResult asyncResult) [0x00063] in C:\j\w
orkspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.cs:605
  at System.IO.FileStream.Read (System.Byte[] array, Int32 offset, Int32 count)
[0x000b1] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.c
s:523
  at MainClass.Main (System.String[] args) <0x3a80f78 + 0x000a8> in <filename un
known>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Invalid parameter
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end
_invoke (object,intptr)
  at (wrapper delegate-end-invoke) <Module>:end_invoke_int__this___IAsyncResult
(System.IAsyncResult)
  at System.IO.FileStream.EndRead (IAsyncResult asyncResult) [0x00063] in C:\j\w
orkspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.cs:605
  at System.IO.FileStream.Read (System.Byte[] array, Int32 offset, Int32 count)
[0x000b1] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.IO\FileStream.c
s:523
  at MainClass.Main (System.String[] args) <0x3a80f78 + 0x000a8> in <filename un
known>:0

Using `csc` produces same error.

I tried it now on Windows 8.1, Windows 7 (both 64 bit) running:
Mono JIT compiler version 4.2.1 (Visual Studio built mono)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-proj
ect.com
        TLS:           normal
        SIGSEGV:       normal
        Notification:  Thread + polling
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

Although runs fine on:
Mono JIT compiler version 4.0.4 (Stable 4.0.4.1/5ab4c0d Wed Sep 16 16:36:37 MDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

Anything else I can try to help pinpoint the problem?
Comment 3 Marek Safar 2015-11-27 15:30:37 UTC
I cannot reproduce this on Mac. Perhaps this is windows specific issue.
Comment 4 Jiri {x2} Cincura 2015-11-30 09:39:18 UTC
Probably. Can I help with that?
Comment 5 Jijie Chen 2016-04-19 05:14:29 UTC
I ran into a problem that caused hangs on razor view file compilation in ASP.NET Core mvc applications. My environment was CentOS 7 and Mono 4.2.3.
Some one reported they encountered similar problems on Debian or Ubuntu systems. Please refer this topic top get more details:  Cannot run ASP.NET 5 default app on Debian 8 Jessie at: https://github.com/aspnet/Hosting/issues/604
Comment 6 Rodrigo Kumpera 2017-10-11 17:24:37 UTC
Hi Niklas,

This looks to be a windows specific issue, could your team take a look at it?