A
Andy B
I am having a problem with a few classes of mine. I have the 3 classes below
(sorry if they are quite huge). When I do the following, I get a Object
reference set to null reference error. Any idea what might be going on? Just
a note that the whole Contract design isn't included since it would be very
huge in size. I also created this class setup with xsd (from an xsd file I
created).
What I did:
//create a new contract
Contract Contract = new Contract();
//create some definitions (word/definition pairs)
Definition TermHost = new Definition();
TermHost.Word="Host";
TermHost.Definition1="The person or persons doing the hiring of the
artist/musician";
//add the definition to the definition cllection class
Contract.Definitions.Add(TermHost);
The classes used:
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace
= "http://tempuri.org/XMLSchema1.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace =
"http://tempuri.org/XMLSchema1.xsd", IsNullable = false)]
public partial class Contract {
private ContractDefinitions definitionsField;
private ContractSections sectionsField;
private Venue venueField;
private Event eventField;
private Host hostField;
private LongDistanceTransport longDistanceTransportField;
private LocalTransport localTransportField;
private Lodging lodgingField;
private Meals mealsField;
private SignatureBlock signaturesField;
public ContractDefinitions Definitions {
get {
return this.definitionsField;
}
set {
this.definitionsField = value;
}
}
public ContractSections Sections {
get {
return this.sectionsField;
}
set {
this.sectionsField = value;
}
}
public Venue Venue {
get {
return this.venueField;
}
set {
this.venueField = value;
}
}
public Event Event {
get {
return this.eventField;
}
set {
this.eventField = value;
}
}
public Host Host {
get {
return this.hostField;
}
set {
this.hostField = value;
}
}
public LongDistanceTransport LongDistanceTransport {
get {
return this.longDistanceTransportField;
}
set {
this.longDistanceTransportField = value;
}
}
public LocalTransport LocalTransport {
get {
return this.localTransportField;
}
set {
this.localTransportField = value;
}
}
public Lodging Lodging {
get {
return this.lodgingField;
}
set {
this.lodgingField = value;
}
}
public Meals Meals {
get {
return this.mealsField;
}
set {
this.mealsField = value;
}
}
public SignatureBlock Signatures {
get {
return this.signaturesField;
}
set {
this.signaturesField = value;
}
}
}
}
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace
= "http://tempuri.org/XMLSchema1.xsd")]
public partial class ContractDefinitions : CollectionBase {
public void Add(Definition Definition) {
List.Add(Definition);
}
public void Remove(int index) {
// Check to see if there is a Definition at the supplied index.
if(index > Count - 1 || index < 0)
// If no Definition exists, a messagebox is shown and the operation
// is cancelled.
{
throw new ArgumentException("Invalid index");
} else {
List.RemoveAt(index);
}
}
public Definition Item(int index) {
return (Definition)List[index];
}
private Definition termsField;
public Definition Terms {
get {
return this.termsField;
}
set {
this.termsField = value;
}
}
}
}
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace =
"http://tempuri.org/XMLSchema1.xsd")]
public partial class Definition {
private string definition1Field;
private string wordField;
[System.Xml.Serialization.XmlElementAttribute("Definition")]
public string Definition1 {
get {
return this.definition1Field;
}
set {
this.definition1Field = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Word {
get {
return this.wordField;
}
set {
this.wordField = value;
}
}
}
}
(sorry if they are quite huge). When I do the following, I get a Object
reference set to null reference error. Any idea what might be going on? Just
a note that the whole Contract design isn't included since it would be very
huge in size. I also created this class setup with xsd (from an xsd file I
created).
What I did:
//create a new contract
Contract Contract = new Contract();
//create some definitions (word/definition pairs)
Definition TermHost = new Definition();
TermHost.Word="Host";
TermHost.Definition1="The person or persons doing the hiring of the
artist/musician";
//add the definition to the definition cllection class
Contract.Definitions.Add(TermHost);
The classes used:
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace
= "http://tempuri.org/XMLSchema1.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace =
"http://tempuri.org/XMLSchema1.xsd", IsNullable = false)]
public partial class Contract {
private ContractDefinitions definitionsField;
private ContractSections sectionsField;
private Venue venueField;
private Event eventField;
private Host hostField;
private LongDistanceTransport longDistanceTransportField;
private LocalTransport localTransportField;
private Lodging lodgingField;
private Meals mealsField;
private SignatureBlock signaturesField;
public ContractDefinitions Definitions {
get {
return this.definitionsField;
}
set {
this.definitionsField = value;
}
}
public ContractSections Sections {
get {
return this.sectionsField;
}
set {
this.sectionsField = value;
}
}
public Venue Venue {
get {
return this.venueField;
}
set {
this.venueField = value;
}
}
public Event Event {
get {
return this.eventField;
}
set {
this.eventField = value;
}
}
public Host Host {
get {
return this.hostField;
}
set {
this.hostField = value;
}
}
public LongDistanceTransport LongDistanceTransport {
get {
return this.longDistanceTransportField;
}
set {
this.longDistanceTransportField = value;
}
}
public LocalTransport LocalTransport {
get {
return this.localTransportField;
}
set {
this.localTransportField = value;
}
}
public Lodging Lodging {
get {
return this.lodgingField;
}
set {
this.lodgingField = value;
}
}
public Meals Meals {
get {
return this.mealsField;
}
set {
this.mealsField = value;
}
}
public SignatureBlock Signatures {
get {
return this.signaturesField;
}
set {
this.signaturesField = value;
}
}
}
}
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace
= "http://tempuri.org/XMLSchema1.xsd")]
public partial class ContractDefinitions : CollectionBase {
public void Add(Definition Definition) {
List.Add(Definition);
}
public void Remove(int index) {
// Check to see if there is a Definition at the supplied index.
if(index > Count - 1 || index < 0)
// If no Definition exists, a messagebox is shown and the operation
// is cancelled.
{
throw new ArgumentException("Invalid index");
} else {
List.RemoveAt(index);
}
}
public Definition Item(int index) {
return (Definition)List[index];
}
private Definition termsField;
public Definition Terms {
get {
return this.termsField;
}
set {
this.termsField = value;
}
}
}
}
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Contracts.ContractModel {
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace =
"http://tempuri.org/XMLSchema1.xsd")]
public partial class Definition {
private string definition1Field;
private string wordField;
[System.Xml.Serialization.XmlElementAttribute("Definition")]
public string Definition1 {
get {
return this.definition1Field;
}
set {
this.definition1Field = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Word {
get {
return this.wordField;
}
set {
this.wordField = value;
}
}
}
}