4

次のコードを検討してください。

public class CountEnum : EnumDataType
    {
        public static readonly CountEnum CANADA = new CountEnum("CA", "Canada");
        public static readonly CountEnum DEFAULT = new CountEnum();
        private static readonly EnumDataTypeList OPTIONS = new EnumDataTypeList();
        public static readonly CountEnum UNITED_STATES = new CountEnum("US", "United States");
        public static readonly CountEnum UNSET = new CountEnum();


        private CountEnum()
        {
        }

        private CountEnum(string code, string name)
        {
            base.code = code;
            base.name = name;
            OPTIONS.Add(this); // This is the line 23
        }

例外の詳細は次のとおりです。

System.TypeInitializationException was caught
  Message=The type initializer for 'CP.BusinessLogic.VConfig' threw an exception.
  Source=CP.BusinessLogic
  TypeName=CP.BusinessLogic.VConfig
  StackTrace:
       at CP.BusinessLogic.VConfig.get_Instance()
       at CP.Fac.CPFac.GetActs() in C:\tfs_src\TeamProject\Main\Source\DApp\CPApp\Fac\CPFac.cs:line 170
  InnerException: System.TypeInitializationException
       Message=The type initializer for 'CP.Types.CountEnum' threw an exception.
       Source=CP.BusinessLogic
       TypeName=CP.Types.CountEnum
       StackTrace:
            at CP.BusinessLogic.VConfig..ctor() in C:\tfs_src\TeamProject\Main\Source\DApp\CPApp\BusinessLogic\VConfig.cs:line 14
            at CP.BusinessLogic.VConfig..cctor() in C:\tfs_src\TeamProject\Main\Source\DApp\CPApp\BusinessLogic\VConfig.cs:line 11
       InnerException: System.NullReferenceException
            Message=Object reference not set to an instance of an object.
            Source=CP.DataObject
            StackTrace:
                 at CP.Types.CountEnum..ctor(String code, String name) in C:\tfs_src\TeamProject\Main\Source\DApp\CPApp\Types\CountEnum.cs:line 23
                 at CP.Types.CountEnum..cctor() in C:\tfs_src\TeamProject\Main\Source\DApp\CPApp\Types\CountEnum.cs:line 8
            InnerException:

実行時にこの例外が発生する理由がわかりません。ビルド エラーは発生せず、コードは正しいように見えます。

4

1 に答える 1