Programing/닷넷

[C#] 내부 배열은 Int32.MaxValue 요소 이상으로 확장할 수 없습니다.

나모찾기 2013. 12. 11. 17:36

현상

System.Runtime.Serialization.SerializationException : 내부 배열은 Int32.MaxValue 요소 이상으로 확장할 수 없습니다.




닷넷 프레임워크의 스펙의 한계이다.


NUnit으로 테스트를 생성했을 때,,

        [Test]

        public void TotalPages_OnlySetCopyColorPage_ShouldBeAsSet(

            [Random(0, 100, 10)] int copyBlackPage,

            [Random(0, 100, 10)] int copyColorPage,

            [Random(0, 100, 10)] int printBlackPage,

            [Random(0, 100, 10)] int printColorPage,

            [Random(0, 100, 10)] int scanPage,

            [Random(0, 100, 10)] int faxPage)

        {

            receipt.CopyBlackPage = copyBlackPage;

            receipt.CopyColorPage = copyColorPage;

            receipt.PrintBlackPage = printBlackPage;

            receipt.PrintColorPage = printColorPage;

            receipt.ScanPage = scanPage;

            receipt.FaxPage = faxPage;


            var sum = copyBlackPage + copyColorPage + printBlackPage + printColorPage +

                scanPage + faxPage;


            Assert.AreEqual(sum, receipt.TotalPages);

        }

와 같은 프로퍼티를 테스트를 생각없이 만들었다.

문제는 Random 프로퍼티는 모든 경우의 수의 조합을 만들기 때문에 10 * 10 * 10 * 10 * 10 * 10 = 1000000개의 경우의 테스트 메소드를 만들려고 시도를 하였다.


결국은 실패가 나버렸다. 결국 닷넷의 내부 배열의 크기는 Int32.MaxValue 가 최대 크기임을 아는 경험을 하였다.

public const int MaxValue = 2147483647;


   1000000

2147483647