Bug 572 - Creating a "large" array results in ArgumentException under .NET
Summary: Creating a "large" array results in ArgumentException under .NET
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2011-08-31 11:41 UTC by Jonathan Pryor
Modified: 2011-08-31 15:16 UTC (History)
1 user (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 NOT_ON_ROADMAP

Description Jonathan Pryor 2011-08-31 11:41:35 UTC
Consider the following source:


    using System;

    enum Foo {
      Bar,
      Baz,
      Gazonk,
      Truc,
      Chose,
      Bidule,
    }

    class Program {

      static void Main ()
      {
        var foos = new [] {
          Foo.Bar,
          Foo.Gazonk,
          Foo.Truc,
          Foo.Chose,
          Foo.Bar,
          Foo.Bidule,
          Foo.Chose,
          Foo.Bidule,
          Foo.Chose,
        };

        foreach (var f in foos) {
          Console.WriteLine (f);
          Console.WriteLine (f);
        }
      }
    }

Compile:

    gmcs example.cs

Mono runs it fine without error. Execution under .NET 4.0 fails:

Unhandled Exception: System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(Array array, RuntimeFieldHandle fldHandle)
   at Program.Main()

This prevents recent versions of Cecil from working under .NET.
Comment 1 Marek Safar 2011-08-31 11:45:13 UTC
Are you running 64bit version of windows ?
Comment 2 Jonathan Pryor 2011-08-31 15:10:39 UTC
Yes, this is on a 64-bit version of Windows.

It doesn't seem to be limited to .NET 4.0 either; the same thing happens on a default Windows 7 installation, which should be .NET 3.0/3.5.
Comment 3 Marek Safar 2011-08-31 15:16:26 UTC
OK, in that case you are hitting known .NET bug.

More details here https://connect.microsoft.com/VisualStudio/feedback/details/635365/runtimehelpers-initializearray-fails-on-64b-framework

If you need 64b .NET workaround initialise the array using array indexer

foos[0] = ..
foos[1] = ..
etc.