静态常量类在添加静态只读属性时导致错误

时间:2012-04-12 10:58:04

标签: c# static windows-services constants readonly

public static class Constants
{

    public const string Fields_Fax = "FAX";
    public const string Fields_DataProtectionPost = "DATAPROTECTIONPOST";
    public const string Fields_DataProtectionTel = "DATAPROTECTIONMOBILE";        
    public const int AddressBookID = 595204;

    public static readonly XName PersonXName = "Person";

此类是在窗口服务解决方案中。该服务已在本地安装,并使用上述值运行。

我接管了这个项目并在这个类中添加了一些我自己的静态只读XName类型。 现在我收到一个错误“当我使用该类中的任何属性时,'This.App'的类型初始化程序引发异常。

只有一个项目,我重新编译了解决方案并重新安装了窗口服务。知道问题是什么吗?

例外是:

"The type initializer for 'Constants' threw an exception"

......内部例外是:

"The ' ' character, hexadecimal value 0x20, cannot be included in a name."

...我评论了我的更改,它正确读取没有错误。所以我只添加了一行,看起来类似于“Person”常量,但导致它失败:

public static readonly XName cor_Tel_GeneralXName = "Tel General";

1 个答案:

答案 0 :(得分:1)

XName用作XML节点,因此受命名XML节点的通常限制。您不能在XML节点的名称中有空格。