-1

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
Community
  • 1
  • 1
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • MSDN Doc. Click VB code example: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.fromtypes(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 I think you just need to say `New Type(){...}` instead of `New (){...}` though. – TyCobb Sep 19 '14 at 00:02

1 Answers1

0

You don't need the 'New' at all - just use:

Dim s As XmlSerializer = XmlSerializer.FromTypes( { GetType(CustomXMLSerializeObject) })(0)
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28
  • Oh, and your code does not compile. It says that the type CustomXMLSerializeObject is not defined. – tmighty Sep 19 '14 at 07:32
  • @tmighty: How does your original C# integrate 'T'? Did you also want someone to define the CustomXMLSerializeObject type for you? This doesn't seem reasonable. – Dave Doknjas Sep 19 '14 at 14:49
  • The original code does not integrate T, but I would like to know how this could be done. – tmighty Sep 19 '14 at 23:41