본문 바로가기

Programing/닷넷

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

현상

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

'Programing > 닷넷' 카테고리의 다른 글

[콜백] System.Action<T>로 함수인자 구현하기 (AsyncWorker)  (0) 2014.01.09
DeviceMock - Func<T> 델리게이터  (0) 2014.01.08
[C#] DateTime.Now 분석  (0) 2013.11.28
[ASP.net] MVC 2  (0) 2013.01.28
윈폼::ESC를 눌러 닫기  (0) 2013.01.11