using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:epcglobal:epcis:xsd:1")]
public partial class ErrorDeclarationExtensionType
private System.Xml.XmlElement[] anyField;
private System.Xml.XmlAttribute[] anyAttrField;
[System.Xml.Serialization.XmlAnyElementAttribute(Namespace = "urn:testXML2", Order = 0)]
public System.Xml.XmlElement[] Any
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr
return this.anyAttrField;
this.anyAttrField = value;
public static void Test()
var example = new ErrorDeclarationExtensionType();
var doc = new XmlDocument();
doc.LoadXml("<testXML2 xmlns=\"urn:testXML2\">anyContents0</testXML2>");
var test = doc.DocumentElement;
var array = new XmlElement[]
var sw = new StringWriter();
var xmlSerializer = new XmlSerializer(example.GetType());
tw = new XmlTextWriter(sw) { Formatting = Formatting.Indented };
xmlSerializer.Serialize(tw, example);
Console.WriteLine(sw.ToString());
ErrorDeclarationExtensionType errorDeclaration;
var xmlSer = new XmlSerializer(typeof(ErrorDeclarationExtensionType));
using (TextReader tr = new StringReader(sw.ToString()))
errorDeclaration = (ErrorDeclarationExtensionType)xmlSer.Deserialize(tr);
Console.WriteLine("Contents of {0}:", nameof(errorDeclaration.Any));
Console.WriteLine(String.Join("\n", errorDeclaration.Any?.Select(e => e.GetOuterXml()) ?? new []{ "null" }));
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 string GetOuterXml(this XmlNode node, bool indent = true)
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings
OmitXmlDeclaration = true,
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
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];