I'm using XmlSerializer in a UWP project. It works fine when compiled for debug but throws PlatformNotSupportedException in release.
I've written a simple example C# program to illustrate this. I have not edited any project settings from what VS 2017 has given me. I have a simple SampleData.xml file in the project as Content. I have classes called SampleItemsForSerialization along with SampleItemList and SampleItem, all marked up to be able to serialize the xml file.
In another class I have the following code:
try
{
using (Stream strmRead = await GetAFileStreamForRead(_strFILENAME))
{
Type typeSampleItems = typeof(SampleItemsForSerialization);
XmlSerializer xmlSerializer = new XmlSerializer(typeSampleItems, new XmlRootAttribute("MyRoot"));
_sampleitems = (SampleItemsForSerialization)xmlSerializer.Deserialize(strmRead);
bLoadedOK = true;
}
catch (Exception ex)
{ ... }
When compiled debug the app works fine, the xml file is deserialized, and I can then show the content of the file in a message dialog.
When compiled for release, the XmlSerializer constructor throws that PlatformNotSupportedException. Searching on this problem has yielded all sorts of talk and supposed solutions that often conflict with one another. My favorite is the build property GenerateSerializationAssemblies. Some say it should be On, others say Off, or maybe Auto, I don't know?
Can anyone make this one simple thing work?
ETA - Anyone wanting to take a crack at this should be able to recreate the problem on their own system: