[英]static constants class causing error when added static readonly property
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";
This class is in a window service solution. 此类在窗口服务解决方案中。 The service was installed locally and was running using the values above.
该服务已本地安装,并使用上述值运行。
I took over the project and added some static readonly XName types of my own to this class. 我接管了该项目,并向此类添加了一些我自己的静态只读XName类型。 Now I get an error "The type initializer for 'This.App' threw an exception" when i use any property from that class.
现在,当我使用该类的任何属性时,将收到错误消息“ This.App的类型初始化器引发异常”。
There is only 1 project and I've recompiled solution and reinstalled the window service. 只有1个项目,我已经重新编译了解决方案并重新安装了窗口服务。 Any idea what the problem is?
知道是什么问题吗?
The exception is: 例外是:
"The type initializer for 'Constants' threw an exception"
...the inner exception is: ...内部例外是:
"The ' ' character, hexadecimal value 0x20, cannot be included in a name."
...I commented out my changes and it was reading correctly with no errors. ...我注释掉我的更改,它可以正确读取,没有错误。 So I added just 1 line which looks similar to the "Person" constant but caused it to fail:
因此,我只添加了1行,看上去与“ Person”常量相似,但导致失败:
public static readonly XName cor_Tel_GeneralXName = "Tel General";
XName
is used as an XML node, and so is subject to the usual restrictions for naming XML nodes. XName
用作XML节点,因此要遵守命名XML节点的通常限制。 You can't have a space in the name of an XML node. XML节点名称中不能有空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.