C# Serializer class Encoding Issue

153 views Asked by At

I'm really not understanding where these characters are coming from. I am populating a custom class object and then serializing it to disk and getting strange characters in the result like this:

<Address1>_x0031_0028_x0020_N_x0020_30th_x0020_PL</Address1>

Where the correct answer is this:

<Address1>10028 N 30th PL</Address1>

When I step through the code, each of these object properties look good, it is only after they serialize that strange characters are injected. What I am not certain of, is if the characters originate from its source (a Nexus DB table which) and I just can't see the strange characters when stepping through the code in VS, or if indeed the characters are a result of serializing from the object itself. FYI, The object class source is actually a schema object that I've converted to a class.

Another note: this problem isn't occurring on every element, just a handful of them.

Thanks for any help on this.

Karl..

1

There are 1 answers

0
kstubs On

Solving my own problem. The problem was that I had defined a field in my schema as xs:ncname type, and then when serializing the values in the data source did not conform to this type so spaces and leading numbers were translated accordingly on serialization.

The solution was to correctly define the field as xs:string.