NSwag build error – Project file does not exist / Unable to retrieve project metadata


While working on a project that used NSwag, when the solution was built, Visual Studio (and dotnet build from the command line) reported the following error: View the code on Gist. Pretty frustrating, as it wasn’t clear what the error meant. This project used NSwag.MSBuild to generate the client on build. As per their documentation, we had an after build target: View the code on Gist. The problem...

Better assertions when verifying Moq’d methods have been called

Man wearing fake glasses and moustache

Moq, according to its GitHub page, is “The most popular and friendly mocking framework for .NET”. Mocking frameworks allow you to create a ‘fake’ version of a dependency (typically an interface, or abstract class). With this fake, you can then instruct the methods return values, or invoke behaviour. Alternatively you can assert the methods were called, with a certain set...

Azure function not receiving json messages using Topic Service Bus Trigger


While developing an Azure Function application, using this tutorial, I encountered a problem. Ultimately, using `func new` generated my function (the run.csx file) which looked like this: public static void Run(string mySbMsg, TraceWriter log) { log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}"); } Side note: the `mySbMsg` is important – it’s defined in the...

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


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


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...