EDN Admin
Well-known member
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.<br/>
at System.Convert.FromBase64String(String s)<br/>
at System.Data.Common.ObjectStorage.ConvertXmlToObject(String s)<br/>
at System.Data.DataColumn.ConvertXmlToObject(String s)<br/>
at System.Data.XmlDataLoader.LoadColumn(DataColumn column, Object[] foundColumns)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTopMostTable(DataTable table)<br/>
at System.Data.XmlDataLoader.LoadData(XmlReader reader)<br/>
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)<br/>
at System.Data.DataSet.ReadXml(XmlReader reader)<br/>
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
http://msdn.microsoft.com/en-us/library/xa669bew.aspx http://msdn.microsoft.com/en-us/library/xa669bew.aspx ) it will always try to base64Decode it, never ever detecting that the original format was hexBinary.
From System.Data.Common:
<span style="color:#1000a0
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; override <span style="color:Blue; object ConvertXmlToObject(<span style="color:Blue; string s)
{
Type dataType = <span style="color:Blue; base.DataType;
<span style="color:Blue; if (dataType == <span style="color:Blue; typeof(<span style="color:Blue; byte[]))
{
<span style="color:Blue; return Convert.FromBase64String(s);
}
.
}
[/code]
Do you have any suggestions how to work around this problem in the framework?
Best Regards,
John
View the full article
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.<br/>
at System.Convert.FromBase64String(String s)<br/>
at System.Data.Common.ObjectStorage.ConvertXmlToObject(String s)<br/>
at System.Data.DataColumn.ConvertXmlToObject(String s)<br/>
at System.Data.XmlDataLoader.LoadColumn(DataColumn column, Object[] foundColumns)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested)<br/>
at System.Data.XmlDataLoader.LoadTopMostTable(DataTable table)<br/>
at System.Data.XmlDataLoader.LoadData(XmlReader reader)<br/>
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)<br/>
at System.Data.DataSet.ReadXml(XmlReader reader)<br/>
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
http://msdn.microsoft.com/en-us/library/xa669bew.aspx http://msdn.microsoft.com/en-us/library/xa669bew.aspx ) it will always try to base64Decode it, never ever detecting that the original format was hexBinary.
From System.Data.Common:
<span style="color:#1000a0
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; override <span style="color:Blue; object ConvertXmlToObject(<span style="color:Blue; string s)
{
Type dataType = <span style="color:Blue; base.DataType;
<span style="color:Blue; if (dataType == <span style="color:Blue; typeof(<span style="color:Blue; byte[]))
{
<span style="color:Blue; return Convert.FromBase64String(s);
}
.
}
[/code]
Do you have any suggestions how to work around this problem in the framework?
Best Regards,
John
View the full article