using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
public string PropertyName { get; set; }
public string OldValue { get; set; }
public string NewValue { get; set; }
[XmlRoot(ElementName="Properties")]
public class Properties {
[XmlElement(ElementName="AProperty")]
public List<AProperty> AProperty { get; set; }
[XmlRoot(ElementName="ObjectTypeProperties")]
public class ObjectTypeProperties {
[XmlElement(ElementName="ObjectType")]
public string ObjectType { get; set; }
[XmlElement(ElementName="ObjectName")]
public string ObjectName { get; set; }
[XmlElement(ElementName="ObjectId")]
public string ObjectId { get; set; }
[XmlElement(ElementName="Properties")]
public Properties Properties { get; set; }
[XmlRoot(ElementName="Properties")]
public class AppEventLogObjectProperties {
[XmlElement(ElementName="ObjectTypeProperties")]
public ObjectTypeProperties ObjectTypeProperties { get; set; }
[XmlRoot(ElementName="AppEventLogObject")]
public class AppEventLogObject {
[XmlElement(ElementName="ObjectId")]
public string ObjectId { get; set; }
[XmlElement(ElementName="Properties")]
public AppEventLogObjectProperties Properties { get; set; }
[XmlElement(ElementName="Description")]
public string Description { get; set; }
public static void Test()
var log = new AppEventLogObject
Properties = new AppEventLogObjectProperties
ObjectTypeProperties = new ObjectTypeProperties
ObjectType = "Agents allowed",
Properties = new Properties
AProperty = new List<AProperty>
new AProperty { PropertyName = "UserID", NewValue = "123", OldValue = "123" },
new AProperty { PropertyName = "Close", NewValue = "No", OldValue = "Yes" },
var xml = log.GetXml(omitStandardNamespaces: true);
XmlAssert.AreEqual(XElement.Parse(xml), XElement.Parse(GetRequiredXml()));
static string GetRequiredXml() =>
<ObjectType>Agents allowed</ObjectType>
<ObjectName>Agents</ObjectName>
<AProperty Name=""UserID"" NewValue=""123"" OldValue=""123""/>
<AProperty Name=""Close"" OldValue=""Yes"" NewValue=""No"" />
<Description>Group</Description>
public static class XmlSerializationHelper
public static T LoadFromXml<T>(this string xmlString, XmlSerializer serial = null)
serial = serial ?? new XmlSerializer(typeof(T));
using (var reader = new StringReader(xmlString))
return (T)serial.Deserialize(reader);
public static string GetXml<T>(this T obj, XmlSerializer serializer = null, bool omitStandardNamespaces = false)
XmlSerializerNamespaces ns = null;
if (omitStandardNamespaces)
ns = new XmlSerializerNamespaces();
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings() { Indent = true };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
(serializer ?? new XmlSerializer(obj.GetType())).Serialize(xmlWriter, obj, ns);
return textWriter.ToString();
public static class XmlAssert
public static void AreEqual(
Assert.IsTrue(XNode.DeepEquals(Normalize(expected), Normalize(actual)));
private static XElement Normalize(XElement element)
.OrderBy(a => a.Name.ToString()),
.OrderBy(a => a.Name.ToString())
.Select(e => Normalize(e)));
.OrderBy(a => a.Name.ToString()));
return new XElement(element.Name, element.Attributes()
.OrderBy(a => a.Name.ToString()), element.Value);
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];