views:

446

answers:

2

I'm pulling my hair out on this one. I'm trying to implement a ADO.Net Data Service that uses a Linq to SQL data context. I thought I had it working, but the URL for one of my tables always gets an exception.

The obvious difference between the table that isn't working and the ones that are, is that the one getting the exception is using a Guid, which is the primary key. The Guid is a UserID, which actually relates to the UserId used by ASP.net Membership. (I'm not exposing the ASP.net Membership tables, but I'm guessing these would break too if I were.)

It is a very simple table: Name: UserDetails :: | Guid UserID | int GroupID (foreign key) | string Name |

Anybody know if there's a trick to getting Guids to work? Or if maybe this is an entirely different problem?

Here's the exception from the service: An error occurred while processing this request.

InnerError: An error occurred while processing this request.

Type: System.InvalidOperationException

StackTrace: t System.Data.Services.Serializers.SyndicationSerializer.WriteComplexObjectValue(Object element, String propertyName, ResourceType expectedType, String relativeUri, DictionaryContent content) at System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded, Object customObject, ResourceType resourceType, Uri absoluteUri, String relativeUri, SyndicationItem item, DictionaryContent content) at System.Data.Services.Serializers.SyndicationSerializer.WriteComplexObjectValue(Object element, String propertyName, ResourceType expectedType, String relativeUri, DictionaryContent content) at System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded, Object customObject, ResourceType resourceType, Uri absoluteUri, String relativeUri, SyndicationItem item, DictionaryContent content) at System.Data.Services.Serializers.SyndicationSerializer.WriteComplexObjectValue(Object element, String propertyName, ResourceType expectedType, String relativeUri, DictionaryContent content) at System.Data.Services.Serializers.SyndicationSerializer.WriteObjectProperties(IExpandedResult expanded, Object customObject, ResourceType resourceType, Uri absoluteUri, String relativeUri, SyndicationItem item, DictionaryContent content) 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.WriteTopLevelElements(IExpandedResult expanded, IEnumerator elements, Boolean hasMoved) at System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults, Boolean hasMoved) at System.Data.Services.ResponseBodyWriter.Write(Stream stream)

+1  A: 

That looks like a bug. I suggest you report it at http://connect.microsoft.com/visualstudio/, then post the URL of your bug report here, so we can vote on it.

John Saunders
A: 

I found the fix to my problem. It actually wasn't related to using a Guid value at all.

I had to add an [IgnoreProperties("User")] to my UserDetail class in Linq to SQL.

The "User" Property is a relation to the "User" class that holds the ASP.Net Memberships user informations (actual table name is aspnet_Users). I have the Linq to SQL "User" class ignored by the data service so I think this must have been the problem.

What threw me way off was that the data service wasn't throwing any errors when I accessed it. With all the other properties, where I either had to add a DataServiceKey() or IgnoreProperties() decoration, when I accessed DataService.svc, I would get an exception complaining about the problem property. For whatever reason, it didn't give me a problem with this one property though, so I wasn't aware anything was wrong. And as you can see above, when I did get an exception, it wasn't useful.

So to any others using Linq To SQL with ADO.Net Data Services, this is the lesson: Make sure you use IgnoreProperties() on any property that references a class you are ignoring.

grimus