Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : Plase help with Deserialization exception



Roy Chastain
4/11/2005 2:25:05 PM
The following code fails with an exception of
"There is an error in XML document (2, 2)." string with an inner exception of "Value cannot be null.\r\nParameter name: input"
string. The inner exception has a strack trace of " at System.Text.RegularExpressions.Regex.Split(String input, Int32
count)\r\n at KMS.Licensing.LicenseBase.Parse() in c:\\kms\\licensing\\common\\licensebase.cs:line 672\r\n at
KMS.Licensing.LicenseBase.set_LicenseBlob(String value) in c:\\kms\\licensing\\common\\licensebase.cs:line 570\r\n at
KMS.Licensing.LicenseBase..ctor(String the_license_blob, Byte[] the_license_signature_blob) in
c:\\kms\\licensing\\common\\licensebase.cs:line 660\r\n at KMS.Licensing.Consumer.License..ctor() in
c:\\kms\\licensing\\consumer\\server\\license.cs:line 72\r\n at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_License(Boolean isNullable, Boolean checkType)\r\n
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read5_License()" string


static public License Deserialize (Stream stream)
{
License new_license = null;
XmlSerializer xml_serial = new XmlSerializer(typeof(License));

try
{
new_license = (License)xml_serial.Deserialize(stream);
}
catch (Exception ex)
{
throw new ApplicationException("Failure importing license file",ex);
}
finally
{
stream.Close();
}
return new_license;
} /* License Deserialize */

The file that is represented by the stream was just serialized by this code

public void Serialize (Stream stream)
{
XmlSerializer xml_serial = new XmlSerializer(typeof(License));

xml_serial.Serialize(stream,this);
stream.Close();
} /* License Serialize */

Any pointers to the problem would be most appreciated


-------------------------------------------
Roy Chastain
v-kevy NO[at]SPAM online.microsoft.com
4/12/2005 12:00:00 AM
Hi Roy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you're trying to deserialize from
an xml document, there is an exception thrown. If there is any
misunderstanding, please feel free to let me know.

Thanks for providing the serialize and deserialize code. But as far as I
can see, the code is correct. So could you please paste your License class
definition and the serialized xml document here? Because according to the
exception message, there might be a field that cannot be null has a null
value in the xml document.

Looking forward to your reply. Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
v-kevy NO[at]SPAM online.microsoft.com
4/12/2005 12:00:00 AM
You're welcome, Roy. Thanks for sharing your experience with all the people
here. If you have any questions, please feel free to post them in the
community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Roy Chastain
4/12/2005 7:06:34 AM
Kevin,
Thanks very much for you comment. It got me to thinking and I realized that things do not work the way I thought. (Not really
sure what I thought....). Anyway, I discovered my problem. The problem was in my class. It was calling RegEx.Split when it
should not have been. I have now changed things and all appears to work.

[quoted text, click to view]

-------------------------------------------
Roy Chastain
AddThis Social Bookmark Button