[UWP] Bug report: DataTable with extended properties deserialization crashes in release mode

Dimitrievits Gergely 1 Reputation point
2021-09-21T08:34:34.777+00:00

When I call this method in an UWP main page in debug (x86) mode everything is works fine the extended properties shown in the message dialog. But when I called in release (x86) mode the ReadXml() method crashes.

The target platform version: 10.0.19041.0 (latest)
with Visual Studio 2019 (16.11.3).

        private async void Test()
        {
            try
            {
                using (DataTable dt = new DataTable("Data"))
                {
                    DataColumn cmn =
                        new DataColumn(
                            "cmn1",
                            typeof(int));

                    cmn.ExtendedProperties.Add("Key1", 5);
                    cmn.ExtendedProperties.Add("Key2", "valami");

                    dt.Columns.Add(cmn);

                    // Serialize
                    string dataTableSer;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        dt.WriteXml(ms, XmlWriteMode.WriteSchema);
                        ms.Position = 0;
                        using (StreamReader sr = new StreamReader(ms))
                        {
                            dataTableSer = sr.ReadToEnd();
                        }
                    }

                    //Deserialize
                    string str = string.Empty;
                    using (StringReader stream = new StringReader(dataTableSer))
                    {
                        using (DataSet ds = new DataSet())
                        {
                            ds.ReadXml(stream);
                            DataTable deSerDt = ds.Tables[0];

                            foreach (DataColumn deSerCmn in deSerDt.Columns)
                                foreach (DictionaryEntry extendedProperty in deSerCmn.ExtendedProperties)
                                    str += extendedProperty.Key + " :" + extendedProperty.Value + Environment.NewLine;

                        }
                    }

                    MessageDialog mb = new MessageDialog(str);
                    await mb.ShowAsync();
                }
            }
            catch (Exception ex)
            {
                MessageDialog mb = new MessageDialog(ex.Message);
                await mb.ShowAsync();
            }
        }

        public MainPage()
        {
            this.InitializeComponent();

            this.Test();
        }
    }
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
{count} votes