Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I tried to serialize a PageSettings object to XML using the standard XmlSerializer class, but upon deserialization it throws an ArgumentNullException with a message Value cannot be null. I investigated it a bit and found that the culprit is the PageSettings.PrinterSettings.PrintFileName property. It's setter throws this exception when the value being set is either null or an empty string. But how am I supposed to serialize the class and later deserialize it when the default value of this property is an empty string? Do I always have to fill in some meaningful value for it?
Posted

1 solution

I don't know an 'official' way to resolve this problem but if no-one comes up with the correct answer you could try the following.

In your serialization method, check PrintFileName and if it is null or empty set it to 'none' or 'empty' or a similar text. Then serialize normally.

In your deserialization method, deserialize normally then check PrintFileName, if it is equal to whatever you used for serialization set it to an empty string.

I hope someone has a real solution for you.

Good luck. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900