- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Adding a custom property to an generated entity
Joined: 02-Jan-2007
hi,
i added a custom attribute in a partial class from an generated entity. this property is a selfdefined class. when i try to save the generated entity (including my property) with the webservice following exception occurs:
Test method BusinessLogic.Test.BasicSettingsManagerFixture.SaveAndGetTest threw exception: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Die Anforderung konnte vom Server nicht gelesen werden. ---> System.InvalidOperationException: Fehler im XML-Dokument (1,16413). ---> System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei SD.LLBLGen.Pro.ORMSupportClasses.XmlHelper.XmlValueToObject(String typeName, String xmlValue)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary`2 processedObjectIDs, List`1 nodeEntityReferences)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlReader reader)
bei System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read22_SaveBasicSettings()
bei Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer40.Deserialize(XmlSerializationReader reader)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
bei System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
bei System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest().
I already inserted the IncludeInCompactXml for my property.
Thx for help, Simone
I don't understand the "looks like german" exception, can you translate it, please.
IncludeInCompactXml is used when you are serializing an entityCollection, and you have added a custom property to this collection which you want to serialize. (property inside the collection class).
Would you please provide a simple repro code with WriteXML() and ReadXML()? You can save the xml into a file and check to see if the property is being serialized or not.
Joined: 02-Jan-2007
The translated exception:
Test method BusinessLogic.Test.BasicSettingsManagerFixture.SaveAndGetTest threw exception: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: The request couldn't be read by the server. ---> System.InvalidOperationException: Error in XML-Document (1,16413). ---> System.NullReferenceException: The object wasn't set to an instance
bei SD.LLBLGen.Pro.ORMSupportClasses.XmlHelper.XmlValueToObject(String typeName, String xmlValue)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary`2 processedObjectIDs, List`1 nodeEntityReferences)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node)
bei SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlReader reader)
bei System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable)
bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read22_SaveBasicSettings()
bei Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer40.Deserialize(XmlSerializationReader reader)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
bei System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
bei System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest().
When i look at the XML-Output from WriteXML, my own property is included there. The problem seems to be, when the generator deserializes the XML to my Object.
Here is the generated xml: The "DefaultPriority" and "Priorities" are our custom attributes
<BasicSettingsEntity DSN="26cc7b95-ae85-46a5-8e67-475ecdba62ea" Assembly="DataObjects, Version=1.0.2561.29381, Culture=neutral, PublicKeyToken=null" Type="DataObjects.EntityClasses.BasicSettingsEntity">
<ConcurrencyPredicateFactory Assembly="Unknown" />
<Validator Assembly="Unknown" />
<DefaultPriority Type="DataObjects.EntityClasses.PriorityEntity">DataObjects.EntityClasses.PriorityEntity</DefaultPriority>
<IsNew Type="System.Boolean">True</IsNew>
<Priorities Type="DataObjects.EntityClasses.PriorityEntity[]">DataObjects.EntityClasses.PriorityEntity[]</Priorities>
<ObjectID Type="System.Guid">ed670c22-9be0-4ab5-9316-1258c366e541</ObjectID>
<Fields>
<DSN>
<CurrentValue Type="System.Guid">26cc7b95-ae85-46a5-8e67-475ecdba62ea</CurrentValue>
<DbValue Type="Unknown"></DbValue>
<IsChanged Type="System.Boolean">True</IsChanged>
<IsNull Type="System.Boolean">False</IsNull>
</DSN>
<Country>
<CurrentValue Type="Unknown"></CurrentValue>
<DbValue Type="Unknown"></DbValue>
<IsChanged Type="System.Boolean">False</IsChanged>
<IsNull Type="System.Boolean">False</IsNull>
</Country>
</Fields>
<IsDirty Type="System.Boolean">True</IsDirty>
<EntityState Type="SD.LLBLGen.Pro.ORMSupportClasses.EntityState">New</EntityState>
<SavedFieldSets />
</BasicSettingsEntity>
Thx again, Simone
What's strange is that with the DefaultPriority property, it can't determine that the property return value is an IEntity2 implementing entity. Because Entity2Xml, the xml producing routine, does:
...
// get all interfaces of the type of this property
Type[] propertyInterfaces = properties[i].PropertyType.GetInterfaces();
bool propertyHandled = false;
for(int j=0;j<propertyInterfaces.Length;j++)
{
// Use waterfall method, check using Equals.
if(propertyInterfaces[j].Equals(typeof(IEntity2)))
{
// a related Entity property which references an entity related to this entity.
XmlNode propertyNode = nodeCreator.AddNode(entityNode, "EntityReference");
nodeCreator.AddAttribute(propertyNode, "PropertyName", properties[i].Name);
XmlNode refEntityNode = null;
EntityBase2 referencedEntity = properties[i].GetValue(this) as EntityBase2;
if(referencedEntity!=null)
{
referencedEntity.Entity2Xml(referencedEntity.LLBLGenProEntityName, parentDocument, processedObjectIDs, aspects, out refEntityNode);
propertyNode.AppendChild(refEntityNode);
}
propertyHandled = true;
break;
}
if(propertyInterfaces[j].Equals(typeof(IEntityCollection2)))
{
// a related entity collection property which references an EntityCollectionBase2 derived class with entities related to this entity.
XmlNode propertyNode = nodeCreator.AddNode(entityNode, "EntityCollectionReference");
nodeCreator.AddAttribute(propertyNode, "PropertyName", properties[i].Name);
XmlNode refEntityCollectionNode = null;
IEntityCollection2 referencedEntityCollection = properties[i].GetValue( this ) as IEntityCollection2;
if(referencedEntityCollection!=null)
{
((IEntityCollectionAccess2)referencedEntityCollection).EntityCollection2Xml(properties[i].Name, parentDocument, processedObjectIDs, aspects, out refEntityCollectionNode);
propertyNode.AppendChild(refEntityCollectionNode);
}
propertyHandled = true;
break;
}
}
...
So it should have an EntityReference element.
mo wrote:
The DefaultPriority property doesn't implement IEntity2. The class is defined by me.
Ah ok. Well, if the property isn't handled by all the custom code, it then simply adds a node with the ToString() value of the property. When deserializing, this indeed goes wrong, as it has the string value, which isn't convertable to the type.
I'm not quite sure what I should do with this. As an entity handles its own xml serialization, the xml serializer isnt used, so if an object is encountered which isnt handleable, it's on its own. I could ask you to implement IXmlSerializable on the class, but that can be a problem as well.
I could try asking XmlSerializer to convert it to xml and back, though I fear that's pretty slow, as the XmlSerializer generates code up front...