DataContractJsonSerializer / Linq oddity? Nope, it’s just me :-(


[Once again the code is on my other machine but…]

So using Microsoft’s Entity Framework with .NET 4 as a data access layer, I select some entity Client objects properties that meet my criteria and take 20 via linq. Something to the effect of:

var clientList = (rom client in entities.Clients where
client.LastName.StartsWith(“min”) select new ClientInfo() { LastName = client.LastName, FirstName = client.FirstName}).Take(20)

So far so good, nothing magical here. I then assign add it as a range to a new List<ClientInfo>

var clientInfos = new List<ClientInfo>();

When the DataContractJsonSerializer hits that list, it correctly does it, however it manages to add in quite a few characters (that’s a null character) into the string which prevents it from properly being parsed by the built in jQuery JSON functions.

Scratch that, I’m likely reading an entire memory stream in instead of just the used portion.

Well, in the end, it’s a good idea to double check your thought process lest you be missing the real problem. I had hacked around my initial noticing of the ’s by replacing them out of the string so I could move on and come back later and figure out what was wrong. Done and done. I’ll verify it of course but I bet you a dollar that’s it. Funny how things come to you out of the blue, like when you’re trying to complain about an oddity. Chances are, the oddity is you Open-mouthed smile