I was using
Dim xs As New XmlSerializer(GetType(T))
but then I realized that I need to change the initialization to
XmlSerializer s = XmlSerializer.FromTypes(new[] { typeof(CustomXMLSerializeObject) })[0];
in order to work around a bug (according to C# XmlSerializer BindingFailure)
However, I am not sure how to get my "T" into it when I try to convert this code to VB.NET.
An online converter told me that the C# code
XmlSerializer s = XmlSerializer.FromTypes(new[] { typeof(CustomXMLSerializeObject) })[0];
should be
Dim s As XmlSerializer = XmlSerializer.FromTypes(New () {GetType(CustomXMLSerializeObject)})(0)
However, this cannot really be correct since the New () raises a compiler error.
Also I am not sure how to add my "T" to it.
Thank you for the help!
My current, faulty code is this:
Public Function DeepClone(Of T)(obj As T) As T
Using ms = New MemoryStream()
Dim xs As XmlSerializer = XmlSerializer.FromTypes(New () {GetType(CustomXMLSerializeObject)})(0)
Return DirectCast(xs.Deserialize(ms), T)
End Using
End Function