Hexadecimal exception. Anybody familiar?

Jun 13, 2008 at 11:51 AM
Hi There,

Sometimes, I get this exception:

System.Xml.XmlException: '', hexadecimal value 0x03, is an invalid character. Line 32026, position 44. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Int32 pos, Char invChar) at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) at System.Xml.XmlTextReaderImpl.ParseText() at System.Xml.XmlTextReaderImpl.ParseElementContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at Facebook.API.FacebookAPI.LoadXMLDocument(String rawXML) at Facebook.API.FacebookAPI.GetUserInfo(String userIds) at Facebook.API.FacebookAPI.GetFriends()

is it a bug in the toolkit? bug in Facebook? bug in my application?

Jun 16, 2008 at 9:52 AM
Edited Jun 16, 2008 at 9:52 AM
Can you be a little more specific please? And if we can see your code, we can help more.
Jun 17, 2008 at 1:45 PM

Simply, this is the code


Collection<Facebook.Entity.User> friendsinfo = this.FBService.GetFriends();

I'm requesting the user's friends.

Someone said that it is a bug with the toolkit. http://forum.developers.facebook.com/viewtopic.php?id=16404

I think the toolkit can not deal with some charactars like this '' ?

what do you think?



Nov 25, 2008 at 7:53 PM
Hi @ all,

I'm new to the FB API, so don't blame me if I write something wrong :)

@topic: I also have the same error, I get a XmlException at

public static users_getInfo_response Parse(string xml) { }
(Line 2999 of the facebook/Schema/LinqToXsdSource.cs file)

after I called

long _fuid = 0123456789
facebook.Schema.user _user = API.users.getInfo(_fuid);

It seems that the XML is not correctly arriving (I don't see any CDATA tags at all). The problem occures if in a field are unknown characters (in my case a 0x0B (Vertical Tab)), but I was unable to retrace this problem by forcing such characters.

I would be very happy if someone coud give me a hint in this case. I tried to catch the error, but this cannot be the solution (I would loose every user info where such a error occurs).

Thanks for your response.

Best regards,
Chris aka Stops
Nov 27, 2008 at 12:49 PM

Does nobody have this problem else?
The problem is that I cannot just ignore the errors, because I need all users from the friends list.
Additionally it is a performance issue too, if I have to load each userInfo seperately (to effectively catch the error), the load time is many times bigger than if I load all users at the same time.

I would be very happy to know if there is any solution or workaround for this problem (no matter how bad the solution is ;)).

Thank you very much for your help.

Dec 4, 2008 at 8:47 AM
Did anyone find a solution?  Any help would be greatly appreciated.

FriendList1.Friends = Master.API.friends.getUserObjects();
causes webapp to crash with...
hexadecimal value 0x10, is an invalid character. Line 1734, position 80.
Description: Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.
 Exception Details: System.Xml.XmlException: '', hexadecimal value 0x10, is an invalid character. Line 1734, position 80.

Dec 4, 2008 at 9:33 AM

I now used a workaround for this problem. What I have seen is that the problem occurs (in my case) at the quotes. The invalid characters are at this XML node, so I just removed the parsing of the quotes in the API.

It woud be intresting where the error occurs in your case. Could you try to build a own API in debug mode (to be able to set breakpoints in the API self) and try to catch the error at the source, where you can see the XML? There you coud open the XML in the Text view and navigate to the line where the error occurs (in your case line 1734), to check the position of the invalid char in the XML (which XMl node).

If there are any other possible workarounds, I'm still very happy to hear them, because my workaround is not a perfect one (what happens if the invalid char is in the Name tag?!?).

Perhaps anyone of the API developers could write a line to put some light in this case? :)

Greetings and have a nice day,
Dec 4, 2008 at 5:51 PM
Thanks MXM_Stops...I took your advice and tried to debug the source.  However, I am running into a compilation issue that leads me to another question.

Has anyone been able to compile the recent 2.0 release SOURCE files?  There appear to be a few missing namespaces/classes??
For example, Facebook.Entity seems to be missing as well as Facebook.Exceptions and Facebook.Parser.  I've searched the entire Source folder and do not find any Entity, Exception, or Parser namespaces or classes.

Here is a link if you would like to see a screenshot of my VS2008 setup for compiling the FB base libraries.  Also shows the errors for missing classes. 
Dec 4, 2008 at 6:22 PM
Hi Jason,

I have also tried to run the API source this way, but this is not possible (don't know why and I don't have spent any time about this issue).

The easyest way would be to load the source into one directory (eg. c:\fbsource\) and open the Facebook.sln Solution file in your VisualStudio.
This way you can open the whole API (with all parts) and you can recompile everything.

After compiling a debug version, you will find the DLL, PBX and XML File in the folder \Facebook.web\bin\Debug\

Now insert all files into your bin directory of your web and voila, you have a debugging release of the API.
(Please be aware of that the pbx file is needed to get the correct reference to the files, so allways import this file into your web too!)

Hope this helps,
Dec 4, 2008 at 7:22 PM
Thanks again.  To save others time too:
The only way i could debug the API with a new web app was to:
1.  compile just the source in its own folder (as mxm_stops suggests above)
2.  copy the following generated dlls into your actual project.
3.  run your new app with normal "Start Debugging"

Dec 5, 2008 at 4:08 PM
FriendList1.Friends = Master.API.friends.getUserObjects();

The above code will cause the web app to bomb if a Facebook member has included certain Ascii/hexadecimal control characters in their profile.  In my case, someone had managed to include a "backspace" in their FB profile.  To resolve, I wrote an XMLHelper class to strip out any hexadecimal entries.

Here is how I resolved.
In facebook/Schema/LinqToXsdSource.cs, I modified users_getInfo_response to cleanup the inbound xml.
1.  add a reference: using facebook.Utility;
2.  add a new line of code:
public static users_getInfo_response Parse(string xml) {
// new code to clean xml.
xml = XMLHelper.CleanXML(xml);
return XTypedServices.Parse<users_getInfo_response>(xml);

Then I added an XMLHelper.cs class.
I put this class file in the facebook\Utility folder.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace facebook.Utility
    class XMLHelper
        // Strip out any hexadecimal characters from xml source.
        public static string CleanXML(string xml)
            if (xml == null) return null;
            StringBuilder newString = new StringBuilder();
            char ch;
            for (int i = 0; i < xml.Length; i++)
                ch = xml[i];
                // Chars in the hex range of: 0-31, and 127 will cause XML parser to fail.
                if ((ch > 31 && ch != 127) || ch == '\t' || ch == '\n' || ch == '\r')
            return newString.ToString();

Dec 11, 2008 at 1:01 AM
FYI, I'm going to start looking into this. It sounds like either FB is returning bad XML, or our parser is blowing up on something it shouldn't (or both).
Dec 11, 2008 at 1:11 AM
Jason, it looks like your code is expecting to use the old version of the toolkit. The new version has completely different namespaces, and a lot of other changes that restructured the code. So whatever that file is that's not compiling in your screenshot will have to be rewritten to match the new code.
Dec 11, 2008 at 7:44 AM
Hi Jon,

Thanks for looking at this issue.
It doesn't seem to be a fault of the Toolkit, because the FB XML should enclose all text data in a <![CDATA[<var>something</var>]]> element (http://en.wikipedia.org/wiki/CDATA), but unfortunately facebook doesn't deliver anything with a CDATA...

Perhaps there is a possibility you can fix this in the toolkit, based on the replacement solution from Jason. That would be perfect. :)

If you need someone for doing some tests, feel free to contact me.

Dec 12, 2008 at 6:27 AM
Thanks so much Jon for your help and contributions!  I really appreciate it.  Let me know if there is any assistance I can provide with testing or coding.  I would be more than willing to help out if needed. The code I mentioned above was for the 2.0  version that I downloaded around 12/5.  Everything is working fine now.

Dec 17, 2008 at 5:08 AM
Does anyone have a good way to get a vertical tab, or one of these other illegal characters, into a Facebook user's name? Step 1 for me is to reproduce the issue, and I'm not sure how to set up a test user. The Windows Character Map apparently doesn't make those characters available. Thoughts?
Dec 17, 2008 at 10:05 AM
Hi John,

perhaps you could convert the illegal characters to a html encoded (or URL encoded) value (for example a | would be a &#124;)? I don't know if this would work (and if for example a Desktop-Application would support such HTML encoded strings), but I would give it a try.