SalesOrder references a Collection of SOLineItems via NavigationProperty.
SOLineItem has a NavigationProperty back to SalesOrder.
Serializing the corresponding IEdmModel with the following code throws a NullReferenceException:
CsdlWriter.TryWriteCsdl(model, writer, CsdlTarget.OData, out errors)
Stacktrace:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.OData.Edm.Csdl.Serialization.EdmModelCsdlSchemaWriter.WriteNavigationPropertyElementHeader(IEdmNavigationProperty member)
at Microsoft.OData.Edm.Csdl.Serialization.EdmModelCsdlSerializationVisitor.BeginElement[TElement](TElement element, Action`1 elementHeaderWriter, Action`1[] additionalAttributeWriters)
at Microsoft.OData.Edm.Csdl.Serialization.EdmModelCsdlSerializationVisitor.ProcessNavigationProperty(IEdmNavigationProperty element)
at Microsoft.OData.Edm.EdmModelVisitor.VisitProperty(IEdmProperty property)
at Microsoft.OData.Edm.EdmModelVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)
at Microsoft.OData.Edm.Csdl.Serialization.EdmModelCsdlSerializationVisitor.ProcessEntityType(IEdmEntityType element)
at Microsoft.OData.Edm.EdmModelVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)
at Microsoft.OData.Edm.Csdl.Serialization.EdmModelCsdlSerializationVisitor.VisitEdmSchema(EdmSchema element, IEnumerable`1 mappings)
at Microsoft.OData.Edm.Csdl.CsdlWriter.WriteSchemas()
at Microsoft.OData.Edm.Csdl.CsdlWriter.WriteODataCsdl()
at Microsoft.OData.Edm.Csdl.CsdlWriter.WriteCsdl()
at Microsoft.OData.Edm.Csdl.CsdlWriter.TryWriteCsdl(IEdmModel model, XmlWriter writer, CsdlTarget target, IEnumerable`1& errors)
When I delete any one of the navigation properties, serialization works.
On a side note, the serialize method uses the TryParse pattern and should never throw an exception.
Instead, errors should be returned via the error out param.
Assemblies affected
Microsoft.OData.Edm 7.2.0
Reproduce steps
Parse the XML above using: CsdlReader.TryParse(XmlReader.Create(metadata), out model, out errors)
Now that you have a model, serialize it using CsdlWriter.TryWriteCsdl(model, writer, CsdlTarget.OData, out errors)
Expected result
TryWriteCsdl does not throw an Exception
Either: Serialization works
Or: In case of errors, these should be in the out -parameter "errors" of TryWriteCsdl.
Actual result
TryWriteCsdl fails with a NullReferenceException. Errors out param is empty, serialization fails (nothing written).
Additional details
The appended XML is reduced to show the main cause.
The original file where the error was first encountered can be found here:
v4_gw_sample_basic.txt
CsdlWriter.TryWriteCsdl fails with NullReferenceException for the following Model:
SalesOrder references a Collection of SOLineItems via NavigationProperty. SOLineItem has a NavigationProperty back to SalesOrder.
Serializing the corresponding IEdmModel with the following code throws a NullReferenceException:
Stacktrace:
When I delete any one of the navigation properties, serialization works. On a side note, the serialize method uses the TryParse pattern and should never throw an exception. Instead, errors should be returned via the error out param.
Assemblies affected
Microsoft.OData.Edm 7.2.0
Reproduce steps
Expected result
TryWriteCsdl does not throw an Exception
Either: Serialization works Or: In case of errors, these should be in the out -parameter "errors" of TryWriteCsdl.
Actual result
TryWriteCsdl fails with a NullReferenceException. Errors out param is empty, serialization fails (nothing written).
Additional details
The appended XML is reduced to show the main cause. The original file where the error was first encountered can be found here: v4_gw_sample_basic.txt