oData deserialization issue in application

248 views Asked by At

I have an odata service that I am referencing in a WPF app. It seems to have an issue deserializing some things. For example, the query below always returns Host as null.

var results = _container.HostVersions.Expand(hv => hv.Host)
                                   .Expand(hv => hv.Version.Service)
                                   .Where(hv => hv.Version.Id == versionId &&
                                          hv.Version.Service.Id == serviceId);

However, if you take the generated resulting URL from this query and paste it in the browser, the JSON shows the Host object. As well, I know the Host object is in the database. So basically for some reason not all of the objects in the Expand call are being deserialized in the application. I have had no luck searching for this issue either on google or on this site. Hoping someone has run into this before.

EDIT:

So before I make the above call, I make this call:

var result = _container.HostVersions
            .Expand(hv => hv.Host)
            .Expand(x => x.Version.Service.Versions)
            .Where(hv => hv.Host.ServerFarmEnvironment.EnvironmentId == environmentId &&
                    hv.Host.ServerFarmEnvironment.ServerFarmId == serverFarmId);

If I put the Expand for Host in there, as seen above, then call the first method in this post, Host is populated. But if I remove the Host expand from this call, the first method in this post has null for Host. It really is so bizarre. Fiddler shows that both responses are the same, as I suspected since the URL resolve properly for the odata. So it has to be some weird deserialization issue that makes no sense.

1

There are 1 answers

4
too On

I can think of 3 possible issues.

Your DataServiceContext can be out of date, have you tried re-generating if from the current project version of OData service? If some properties on the Host class do not match or if the namespace has changed/does not match - the Expand won't be able to get any of the objects of the type Host.

Also you can check if Host class namespace is recognized by client. You can do this by grabbing all Host objects from the service (if your schema allows this) or alternatively create a query for host type objects on your service which will return one or more testing Host instances. If those won't also work - you need to fix namespace recognition issues.

Another issue might be MaxExpansionDepth set to 0 or other permissions limits.