I am currently in the process of developing an application using C# (.Net).
I have used XSD.exe utlity to generate CLR Types from an XSD.
It has resulted in sevral parent and sub-classes.
Here's an example:
Suppose we have a parent class named "Employee" which has a partial or a sub class named "Department".
The code works fine when I assign value to one of the properties of "Employee" class but returns an error "Object should be instantiated" (for the child class) when I try to assign a value to the property of the Child class.
Please let me know if you come across any solution to the problem.
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Yes, you do. It doesn't instantiate those because it needs to know the difference between properties with a null reference and properties which have object references. This is the only way that the serializers can know wether to create xml similar to:
<Employee>
... employee properties here
</Employee>
or:
<Employee>
<Department>
... department properties here
<Department>
... employee properties here
</Employee>
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
raringsunny
Member
133 Points
109 Posts
XSD to CLR Classes
Sep 17, 2011 07:17 AM|LINK
Hi,
I am currently in the process of developing an application using C# (.Net).
I have used XSD.exe utlity to generate CLR Types from an XSD.
It has resulted in sevral parent and sub-classes.
Here's an example:
Suppose we have a parent class named "Employee" which has a partial or a sub class named "Department".
The code works fine when I assign value to one of the properties of "Employee" class but returns an error "Object should be instantiated" (for the child class) when I try to assign a value to the property of the Child class.
Please let me know if you come across any solution to the problem.
Regards,
Manoj
xsd
robert.weste...
Contributor
2352 Points
399 Posts
Re: XSD to CLR Classes
Sep 17, 2011 07:48 AM|LINK
Hi Manoj,
I guess you have code similar to the following:
Have you tried instantiating the Department property like so:
Hope it helps!
/Robert
xsd
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
raringsunny
Member
133 Points
109 Posts
Re: XSD to CLR Classes
Sep 19, 2011 04:05 PM|LINK
Thanks for your reply Robert.
Question is - Do I have to instantiate the Department property using the new keyword?
There are number of such properties in the parent class and also some nested classes underneath the child classes.
xsd
robert.weste...
Contributor
2352 Points
399 Posts
Re: XSD to CLR Classes
Sep 20, 2011 11:09 AM|LINK
Hi,
Yes, you do. It doesn't instantiate those because it needs to know the difference between properties with a null reference and properties which have object references. This is the only way that the serializers can know wether to create xml similar to:
or:
<Employee> <Department> ... department properties here <Department> ... employee properties here </Employee>/Robert
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.