"Object reference not set to an instance of an object" exception in SyndicationSerializer
-
Thursday, April 22, 2010 7:22 AM
We receive this error (full exception at the end of the post) on the following url:
http://localhost:2948/FourWerkService.svc/EreignisSet(6)?$expand=PersonEreignis/Person/PersonGrad/Grad
As soon as we take the Grad expand away it works:
http://localhost:2948/FourWerkService.svc/EreignisSet(6)?$expand=PersonEreignis/Person/PersonGrad
The model is as follow:
[Ereignis] 1---n [PersonEreignis] n---1 [Person] 1---n [PersonGrad] n---1 [Grad]
In this case the [Ereignis] has only one [PersonEreignis], therefore only one [Person], who has no [PersonGrad] and therefore any [Grad]
This url gives no problem:
http://localhost:2948/FourWerkService.svc/PersonSet(418)?$expand=PersonGrad/GradWhat is wrong with it? Should something else specified in the url? Is that a bug? Is there a work around?
Thanks in advance
Full exception:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<entry xml:base="http://localhost:2948/FourWerkService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<id>http://localhost:2948/FourWerkService.svc/EreignisSet(6)</id>
<title type="text"></title>
<updated>2010-04-20T08:59:24Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Ereignis" href="EreignisSet(6)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonEreignis" type="application/atom+xml;type=feed" title="PersonEreignis" href="EreignisSet(6)/PersonEreignis">
<m:inline>
<feed>
<title type="text">PersonEreignis</title>
<id>http://localhost:2948/FourWerkService.svc/EreignisSet(6)/PersonEreignis</id>
<updated>2010-04-20T08:59:24Z</updated>
<link rel="self" title="PersonEreignis" href="EreignisSet(6)/PersonEreignis" />
<entry>
<id>http://localhost:2948/FourWerkService.svc/PersonEreignisSet(32)</id>
<title type="text"></title>
<updated>2010-04-20T08:59:24Z</updated>
<author>
<name />
</author>
<link rel="edit" title="PersonEreignis" href="PersonEreignisSet(32)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Ereignis" type="application/atom+xml;type=entry" title="Ereignis" href="PersonEreignisSet(32)/Ereignis" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Person" type="application/atom+xml;type=entry" title="Person" href="PersonEreignisSet(32)/Person">
<m:inline>
<entry>
<id>http://localhost:2948/FourWerkService.svc/PersonSet(418)</id>
<title type="text"></title>
<updated>2010-04-20T08:59:24Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Person" href="PersonSet(418)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonEreignis" type="application/atom+xml;type=feed" title="PersonEreignis" href="PersonSet(418)/PersonEreignis" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonAusbildung" type="application/atom+xml;type=feed" title="PersonAusbildung" href="PersonSet(418)/PersonAusbildung" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonAusweiskategorie" type="application/atom+xml;type=feed" title="PersonAusweiskategorie" href="PersonSet(418)/PersonAusweiskategorie" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonFeuerwache" type="application/atom+xml;type=feed" title="PersonFeuerwache" href="PersonSet(418)/PersonFeuerwache" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonFunktion" type="application/atom+xml;type=feed" title="PersonFunktion" href="PersonSet(418)/PersonFunktion" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PersonGrad" type="application/atom+xml;type=feed" title="PersonGrad" href="PersonSet(418)/PersonGrad">
<m:inline>
<feed>
<title type="text">PersonGrad</title>
<id>http://localhost:2948/FourWerkService.svc/PersonSet(418)/PersonGrad</id>
<updated>2010-04-20T08:59:24Z</updated>
<link rel="self" title="PersonGrad" href="PersonSet(418)/PersonGrad" />
<m:error>
<m:code></m:code>
<m:message xml:lang="de-CH">An error occurred while processing this request.</m:message>
<innererror xmlns="xmlns">
<message>Object reference not set to an instance of an object.</message>
<type>System.NullReferenceException</type>
<stacktrace> at System.Data.Services.Serializers.SyndicationSerializer.WriteOtherElements(String title, String linkRelation, Uri absoluteUri, String relativeUri, SyndicationItem item)
at System.Data.Services.Serializers.SyndicationSerializer.WriteEntryElement(IExpandedResult expanded, Object element, Type expectedType, Uri absoluteUri, String relativeUri, SyndicationItem target)
at System.Data.Services.Serializers.SyndicationSerializer.<DeferredFeedItems>d__0.MoveNext()
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItems(XmlWriter writer, IEnumerable`1 items, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeedTo(XmlWriter writer, SyndicationFeed feed, Boolean isSourceFeed)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeed(XmlWriter writer)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteTo(XmlWriter writer)
at System.Data.Services.Serializers.SyndicationSerializer.InlineAtomFeed.WriteXml(XmlWriter writer)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteIXmlSerializable(XmlWriterDelegator xmlWriter, Object obj, XmlSerializableWriter xmlSerializableWriter)
at System.Runtime.Serialization.XmlDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)
at System.ServiceModel.Syndication.SyndicationElementExtension.ExtensionDataWriter.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtension.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtensionCollection.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.ExtensibleSyndicationObject.WriteElementExtensions(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationLink.WriteElementExtensions(XmlWriter writer, String version)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteLink(XmlWriter writer, SyndicationLink link, Uri baseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItemContents(XmlWriter dictWriter, SyndicationItem item, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10ItemFormatter.WriteItem(XmlWriter writer)
at System.ServiceModel.Syndication.Atom10ItemFormatter.WriteTo(XmlWriter writer)
at System.Data.Services.Serializers.SyndicationSerializer.InlineAtomItem.WriteXml(XmlWriter writer)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteIXmlSerializable(XmlWriterDelegator xmlWriter, Object obj, XmlSerializableWriter xmlSerializableWriter)
at System.Runtime.Serialization.XmlDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)
at System.ServiceModel.Syndication.SyndicationElementExtension.ExtensionDataWriter.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtension.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtensionCollection.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.ExtensibleSyndicationObject.WriteElementExtensions(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationLink.WriteElementExtensions(XmlWriter writer, String version)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteLink(XmlWriter writer, SyndicationLink link, Uri baseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItemContents(XmlWriter dictWriter, SyndicationItem item, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItem(XmlWriter writer, SyndicationItem item, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItems(XmlWriter writer, IEnumerable`1 items, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeedTo(XmlWriter writer, SyndicationFeed feed, Boolean isSourceFeed)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteFeed(XmlWriter writer)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteTo(XmlWriter writer)
at System.Data.Services.Serializers.SyndicationSerializer.InlineAtomFeed.WriteXml(XmlWriter writer)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteIXmlSerializable(XmlWriterDelegator xmlWriter, Object obj, XmlSerializableWriter xmlSerializableWriter)
at System.Runtime.Serialization.XmlDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)
at System.ServiceModel.Syndication.SyndicationElementExtension.ExtensionDataWriter.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtension.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationElementExtensionCollection.WriteTo(XmlWriter writer)
at System.ServiceModel.Syndication.ExtensibleSyndicationObject.WriteElementExtensions(XmlWriter writer)
at System.ServiceModel.Syndication.SyndicationLink.WriteElementExtensions(XmlWriter writer, String version)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteLink(XmlWriter writer, SyndicationLink link, Uri baseUri)
at System.ServiceModel.Syndication.Atom10FeedFormatter.WriteItemContents(XmlWriter dictWriter, SyndicationItem item, Uri feedBaseUri)
at System.ServiceModel.Syndication.Atom10ItemFormatter.WriteItem(XmlWriter writer)
at System.ServiceModel.Syndication.Atom10ItemFormatter.WriteTo(XmlWriter writer)
at System.Data.Services.Serializers.SyndicationSerializer.WriteTopLevelElement(IExpandedResult expanded, Object element)
at System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults, Boolean hasMoved)
at System.Data.Services.ResponseBodyWriter.Write(Stream stream)</stacktrace>
</innererror>
</m:error>
All Replies
-
Thursday, April 22, 2010 4:13 PMModerator
Hi,
What provider are you using? Reflection, EF, LINQ to SQL, something else...
I don't see anything right now in the method the exception occurs. Could you try to attach a debugger and see what local variables (parameters) you might see and post their values here? I'm especially interested in null values :-)
Thanks,
Vitek Karas [MSFT] -
Monday, April 26, 2010 7:34 AM
I'm using EF but from the exception you can see that I can't attach a debugger the whole stack trace is inside the System namespace, I can only tell you that I know that there is only one Person without PersonGrad. So those two url return the same atom-xml response:
http://localhost:2948/FourWerkService.svc/EreignisSet(6)?$expand=PersonEreignis/Person
http://localhost:2948/FourWerkService.svc/EreignisSet(6)?$expand=PersonEreignis/Person/PersonGrad
But as soon as I add also to expand the Grad it throws the exception.
-
Monday, April 26, 2010 3:40 PMModerator
Hi,
You can attach a debugger even if the exception happens inside the .NET framework. It will not show you source code (although that is also possible for most .NET framework libraries), but it will definitely show you some local variables.
What version of the .NET framework (and WCF Data Services) are you using?
Thanks,
Vitek Karas [MSFT] -
Tuesday, April 27, 2010 9:19 AM
.Net 3.5 SP1 (or 2, the latest one) and WCF Data Services 1.0 but I have found this thread, I think is the same bug:
http://social.msdn.microsoft.com/Forums/en-US/dataservices/thread/19b77448-237c-4825-b89d-1aff0667c0f6
-
Tuesday, April 27, 2010 4:00 PMModerator
Hi,
Could you please try to upgrade to our lates version for .NET 3.5 and see if the problem is fixed?
Thanks a lot,
Vitek Karas [MSFT] -
Wednesday, April 28, 2010 2:51 PM
At the moment we have installed the application on a machine with .Net 4.0 and the error is disappeared, we are considering to migrate the project to .Net 4.0- Proposed As Answer by Vitek Karas - MSFTMicrosoft Employee, Moderator Wednesday, April 28, 2010 3:35 PM

