using System;
using System.Runtime.Serialization;
using System.IO;
using Newtonsoft.Json;
using System.Xml.Linq;
using System.Linq;
using NUnit.Framework; // Throws NUnit.Framework.AssertionException
//https://stackoverflow.com/questions/64611423/cant-deserialize-xml-using-datacontractserializer
public class Program
{
public static void Main()
var request="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <s:Body>\r\n <ProcessOneWayEvent xmlns=\"http://schemas.microsoft.com/sharepoint/remoteapp/\">\r\n <properties xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <CultureLCID>1033</CultureLCID>\r\n </properties>\r\n </ProcessOneWayEvent>\r\n </s:Body>\r\n</s:Envelope>";
Console.WriteLine(request);
var response=XmlDeserializer<Envelope>(request);
//here problem always null ProcessOneWayEvent , i can't change the xml document so is there any woraround with this in netcore without using xmlsreializer
Console.WriteLine(JsonConvert.SerializeObject(response));
Assert.AreEqual(1033, response.Body.ProcessOneWayEvent.Properties.CultureLCID);
}
public static T XmlDeserializer<T>( string text)
using (Stream stream = new MemoryStream())
byte[] data = System.Text.Encoding.UTF8.GetBytes(text);
stream.Write(data, 0, data.Length);
stream.Position = 0;
var deserializer = new DataContractSerializer(typeof(T));
return (T)deserializer.ReadObject(stream);
// FIXED namespace in the following
[DataContract(Name = "Body", Namespace = "http://schemas.microsoft.com/sharepoint/remoteapp/")]
public class Body
[DataMember(Name = "ProcessOneWayEvent")]
public ProcessOneWayEvent ProcessOneWayEvent;
[DataContract(Name = "properties", Namespace = "http://schemas.microsoft.com/sharepoint/remoteapp/")]
public class SPRemoteEventProperties
[DataMember(Name = "CultureLCID") ]
public int CultureLCID { get; set; }
// The following are UNCHANGED
[DataContract(Name = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
[DataMember(Name = "Body")]
public Body Body;
[DataContract(Name = "ProcessOneWayEvent",Namespace = "http://schemas.microsoft.com/sharepoint/remoteapp/")]
public class ProcessOneWayEvent
[DataMember(Name = "properties")]
public SPRemoteEventProperties Properties { get; set; }