When parsing entry of type hexBinary i get "Invalid length for a Base-64 char array RRS feed

  • Question

  • Hi!

    I use an existing XSD with multiple binary values, encoded as hexBinary according to the XSD. The file is used for interop between the system I build and an existing system. I have created a dataset in VS by specifing the custom tool "MSDataSetGenerator".

    Whenever I load an xml file with a hex encoded value, for example 01, I get the following Exception.

    System.FormatException: Invalid length for a Base-64 char array.
       at System.Convert.FromBase64String(String s)
       at System.Data.Common.ObjectStorage.ConvertXmlToObject(String s)
       at System.Data.DataColumn.ConvertXmlToObject(String s)
       at System.Data.XmlDataLoader.LoadColumn(DataColumn column, Object[] foundColumns)
       at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)
       at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)
       at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)
       at System.Data.XmlDataLoader.LoadTopMostTable(DataTable table)
       at System.Data.XmlDataLoader.LoadData(XmlReader reader)
       at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
       at System.Data.DataSet.ReadXml(XmlReader reader)
       at My.Own.ClassName...ctor(Logger log, IInputFileReader fileReader)

    When using Reflector *cough* to look into System.Data.Common.ObjectStorage.ConvertXmlToObject it looks like if the resulting data is supposed to be byte[] (which both hexBinay and base64Binary is according to it will always try to base64Decode it, never ever detecting that the original format was hexBinary.

    From System.Data.Common:

    public override object ConvertXmlToObject(string s)
     Type dataType = base.DataType;
     if (dataType == typeof(byte[])) 
      return Convert.FromBase64String(s);

    As the c# code for the dataset is generated automaticly by MSDataSetGenerator I would like some way to "hook" into the loading of the xml to be able to correct the faulty behaviour of the framework. Is there a way to do that?

    Best Regards,


    Wednesday, April 27, 2011 2:23 AM

All replies


    Hi John,


    According to your description, I want to let ConvertXmlToObject method detect the original format, right. I'm not familiar with XML, XML type: hexBinary and base64Binary map byte[] in CLR type. The method in CLR just cares byte[] type. I think you can customize the tool and write the extension method.  I will do some research, thanks for understanding.

    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 27, 2011 6:37 AM