简体   繁体   中英

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. Now I get an error "The type initializer for 'This.App' threw an exception" when i use any property from that class.

There is only 1 project and I've recompiled solution and reinstalled the window service. 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:

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. You can't have a space in the name of an XML node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM