---
lang: ja-jp
breaks: true
---
# C# パラメータ(引数)が多い(かなり多い)基底クラスのコンストラクタを明示的に呼び出す場合に、実行時に「System.StackOverflowException」が発生する。 2021-04-18
## 検証環境
* Visual Studio 2017
* .Net Framework 4.7.2
## 現象
以下のように基底クラスのコンストラクタを明示的に呼び出した場合、パラメータ(引数)が400を超えたあたりで、実行時に「System.StackOverflowException」が発生した。
※コンパイルは不通に通ります。
```csharp=
public class 派生クラス : 基底クラス
{
public 派生クラスのコンストラクタ(
IList<int> aaaa_1,
IList<int> aaaa_2,
IList<int> aaaa_3,
・・・
IList<int> aaaa_400
)
: base(
aaaa_1 /* ちょっとした変換処理有り */,
aaaa_2 /* ちょっとした変換処理有り */,
aaaa_3 /* ちょっとした変換処理有り */,
・・・
aaaa_400 /* ちょっとした変換処理有り */
)
{
}
}
```
## 回避策
しょうがないので、以下の様に対応すると発生しなくなった。
※「ちょっとした変換処理有り」の処理の内容に応じて、「System.StackOverflowException」が発生する。
```csharp=
public class 派生クラス : 基底クラス
{
public 派生クラスのコンストラクタ(
IList<int> aaaa_1,
IList<int> aaaa_2,
IList<int> aaaa_3,
・・・
IList<int> aaaa_400
)
: base(
// パラメータが増えた場合にコンパイルエラーとしたい為、
// 基底クラスのコンストラクタを明示的に呼び出す処理は残したい。
aaaa_1 : null,
aaaa_2 : null,
aaaa_3 : null,
・・・
aaaa_400: null
)
{
base.aaaa_1 = aaaa_1 /* ちょっとした変換処理有り */,
base.aaaa_2 = aaaa_2 /* ちょっとした変換処理有り */,
base.aaaa_3 = aaaa_3 /* ちょっとした変換処理有り */,
・・・
base.aaaa_400 = aaaa_400 /* ちょっとした変換処理有り */
}
}
```
## 2021-04-19 追記 .Netアプリのスタックサイズは変更できるらしい。
> C#(WPF)アプリのスタックサイズの変更方法
> 【使い方】
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\editbin.exe" "targetApplication.exe" /STACK:4194304
4194304⇒4MB
> https://qiita.com/hiroed1218/items/d2caf33378961b02ec9e
###### tags: `C#` `StackOverflowException`