using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
public static void Test()
var fooNs = "http://www.example.com/xmlns/foo-version1";
var defNs = "http://www.example.com/xmlns";
var doc = new XmlDocument();
var root = doc.CreateElement("foo", "document", fooNs);
var defAttr = doc.CreateAttribute("xmlns");
root.Attributes.Append(defAttr);
var bar = doc.CreateElement("foo", "bar", fooNs);
var bazAttr = doc.CreateAttribute("foo", "baz", fooNs);
bazAttr.Value = XmlConvert.ToString(true);
bar.Attributes.Append(bazAttr);
var xmlnsNs = "http://www.w3.org/2000/xmlns/";
var fooAttr = doc.CreateAttribute("xmlns", "foo", xmlnsNs);
root.Attributes.Append(fooAttr);
var xml = doc.GetOuterXml();
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(GetRequiredXml())));
static string GetRequiredXml()
return @"<foo:document xmlns=""http://www.example.com/xmlns"" xmlns:foo=""http://www.example.com/xmlns/foo-version1"">
<foo:bar foo:baz=""true"" />
public static class XmlSerializationHelper
public static string GetOuterXml(this XmlNode node, bool indent = true, bool omitXmlDeclaration = true)
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings { Indent = indent, OmitXmlDeclaration = omitXmlDeclaration };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
return textWriter.ToString();
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];