0

is it possible to use a class created by xsd.exe or by paste to XML as class (VS13), as a normal object? The situation is this, I have a WebService(WS) that receives an Xml and returns an answer (captain obvious). The xsd as 2000+ lines, so I would like to be able to work with this class that was created and when I wanted to send the info I would serialize it again and send it.

The problem is that when I do the class foo = new class() it's empty/null, no error is given except the NullReferenceException. For what I can understand the problem should be coming from the constructor. The empty constructor is created but as no parameters.

So my question is how can I use the class as a normal one, because 2000+ lines file as a lot of attributes that I would like to avoid to be rewritten. What kind of constructor do I have to write or method to generate\create the object.

Edited after the marked this question as duplicate: I say in my question that it gives the NullReferenceException probably because no arguments on the constructor and so it isn't initialized. But for me to initialize it would be very hard (time consuming aka boring) because there are more than 200 partial classes in this class. If that is the only way then so be it. I'm here asking if there is an alternative. Sorry if I didn't explain myself well. Should I ask again due to the marked as duplicate?

Morce
  • 51
  • 1
  • 10
  • 1
    It sounds like you want to deserialize an XML string. Take a look at the Deserialize method for XmlSerializer: https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.deserialize(v=vs.110).aspx – Aaron Yarborough Nov 30 '15 at 11:06
  • @AaronYarborough Hi, first thank you for answering. To deserialize you need to have the xml file to populate the class, stream to the class. I want to do this without having an xml file. Imagine a program where you are filling a form and want to use the class generated by the xsd and only later serialize to send. My problem is how to do a constructor for this class. I can use multiple objects of the class but that would make me create more than 200 "mini" objects. I would like to only create one object and run the hierarchy on it. – Morce Nov 30 '15 at 12:49
  • For the marked this question as duplicate, I said in my question that it gives the NullReferenceException probably because no arguments on the constructor and so it is no initialized. But for me to initialize it would be very hard (time consuming aka boring) because there are more than 200 partial classes in this class. If that is the only way then so be it. I'm here asking if there is an alternative. Sorry if I didn't explain myself whell – Morce Nov 30 '15 at 12:57
  • Apologies, I've wildly misunderstood your question. Put it down to the fact I'm on a bit of a caffeine frenzy? – Aaron Yarborough Nov 30 '15 at 13:11
  • Much of software development is time consuming and "boring". You need to get over that. There's no magic syntax to initialize reference-type properties automatically. – D Stanley Nov 30 '15 at 14:51

0 Answers0