Tag.net

Out Of Memory exception when deserializing with JSON.net – Use Streams instead

O

Calling an api and deserializing the returned json into a type is something I have to do quite often. I used to use the following: //assume client is an instance of HttpClient - this part isn't important var response = await client.PostAsync(url, content); //read the response as a string var responseString = await response.Content.ReadAsStringAsync(); //use json.net to deserialize this into a...

Mocking calls to ApplicationContext.Current.Services

M

My current contract involves working on a project based on Umbraco. Unit testing Umbraco, can be a bit tricky, especially given the existence of the static ApplicationContext.Current.Services class, which contains handy references to the Umbraco services – provided by a static type! We can’t mock this. So, I created a little wrapper around this that would allow us to mock the returned service...

Could not load file or assemebly ‘ceTe.DynamicPDF.Rasterizer.40.x86.dll’

C

I ran into this issue when deploying an application that uses the DynamicPDF Rasterizer. After emailing support, who got back to me within the promised 24 hours, they offered some good suggestions. The solution for me was to use the installer provided on their download page, which in turn installs the pre-requisites (Visual C++ distributable) Secondly, I changed the reference in my project to the...

.net project unit test naming

Just wanted to do a quick post on unit test method naming, in particular with .net projects; Most test suites I come across are title cased: public void LikeThis() This annoys me. I find long method names hard to read, and easy to miss detail Example: public void DoesNotReImplementAdditionalInterfaceAlreadyImplementedByInterceptedClass() is not a readable as: public void...

Removing $id from JSON returned by WebApi

R

If you’re using the default JSON formatter (ie- haven’t set another one up) your outputted JSON may look something like this: [ { $id: "1", FirstName: "John", LastName: "Smith", }, { $id: "2", FirstName: "Sarah", LastName: "Harris", }, { $id: "3", FirstName: "Michael", LastName: "Jones", }, { $id: "4", FirstName: "Harry", LastName: "Green", } ] Notice the $id element appearing. What...