Bug 20591 - MemoryMappedFile CreateNew aborts on using statement
Summary: MemoryMappedFile CreateNew aborts on using statement
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Core ()
Version: unspecified
Hardware: PC Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2014-06-14 12:08 UTC by Miguel de Icaza [MSFT]
Modified: 2014-08-06 10:03 UTC (History)
2 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 on GitHub or Developer Community 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 Miguel de Icaza [MSFT] 2014-06-14 12:08:41 UTC
The following program crashes with a nullref:

using System.IO;
using System.IO.MemoryMappedFiles;

namespace TestProject
{
    public class TestClass
    {
        static void Main ()

        {
            var fileName = "Roslyn Temp Storage 8192 a5fbd5c6992c4b0996e88c627cf685f5";
            if (File.Exists(fileName))
                File.Delete(fileName);
            var memoryMappedFile90 = MemoryMappedFile.CreateNew(fileName, 4194304, MemoryMappedFileAccess.ReadWrite);
            var stream = memoryMappedFile90.CreateViewStream(4186112, 3222, MemoryMappedFileAccess.Write);
            using (var tw = new StreamWriter(stream))
            {
                tw.WriteLine("Hello World!");
            }
        }
    }
}

Log:

System.NullReferenceException: Object reference not set to an instance of an object
  at System.String.memcpy4 (System.Byte* dest, System.Byte* src, Int32 size) [0x00000] in <filename unknown>:0 
  at System.String.memcpy (System.Byte* dest, System.Byte* src, Int32 size) [0x00000] in <filename unknown>:0 
  at System.IO.UnmanagedMemoryStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.FlushBytes () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.FlushCore () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.Flush () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
  at System.IO.TextWriter.Dispose () [0x00000] in <filename unknown>:0 
  at TestProject.TestClass.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at System.String.memcpy4 (System.Byte* dest, System.Byte* src, Int32 size) [0x00000] in <filename unknown>:0 
  at System.String.memcpy (System.Byte* dest, System.Byte* src, Int32 size) [0x00000] in <filename unknown>:0 
  at System.IO.UnmanagedMemoryStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.FlushBytes () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.FlushCore () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.Flush () [0x00000] in <filename unknown>:0 
  at System.IO.StreamWriter.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
  at System.IO.TextWriter.Dispose () [0x00000] in <filename unknown>:0 
  at TestProject.TestClass.Main () [0x00000] in <filename unknown>:0
Comment 1 Miguel de Icaza [MSFT] 2014-06-17 12:34:35 UTC
The crash is really any attempts to write anything to the stream, even a WriteByte will cause this.
Comment 2 Rodrigo Kumpera 2014-06-19 14:33:03 UTC
Fixed in master.
Comment 3 Saurabh 2014-08-06 10:03:14 UTC
I have checked this Issue with mentioned code and this is working fine at my end. This is the screencast for the same: http://www.screencast.com/t/jzDfrbS0O

=== Xamarin Studio ===

Version 5.3 (build 412)
Installation UUID: 2591d519-875d-4afe-a3d9-5fcf391bbd2d
Runtime:
	Mono 3.8.0 ((no/9ffca33)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000002

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/nischal/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

=== Apple Developer Tools ===

Xcode 4.6.3 (2068)
Build 4H1503

=== Xamarin.iOS ===

Version: 7.4.0.89 (Business Edition)
Hash: 189801d
Branch: 
Build date: 2014-08-05 19:34:46-0400

=== Xamarin.Mac ===

Version: 1.10.0.4 (Business Edition)

=== Build Information ===

Release ID: 503000412
Git revision: 77e042831804079a649ee83092ed36c7c10773a2
Build date: 2014-08-01 06:32:22-04
Xamarin addins: 57e379e6a9454a1c0d97aa3f770e7ae7cc16c522

=== Operating System ===

Mac OS X 10.7.4
Darwin nischals-Mac-mini.local 11.4.0 Darwin Kernel Version 11.4.0
    Mon Apr  9 19:32:15 PDT 2012
    root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64