考虑这段代码:
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:
我无法弄清楚为什么我会在运行时收到此异常。我没有收到任何构建错误,并且代码看起来正确。