Category: .NET

foreach image in a resource file

Resource files are a very useful addition to the .NET framework as they allow easy storage and retrival of data e.g.

In order to iterate through the all the resources in the resource file, we have to use ResourceSet. To get it we need run a resource manager on our resource file. The complete

Continue Reading

How to display an image on the website from a binary source (e.g. a database)

There are various ways in which one could display an image on the website form a binary source. One solution would invole simply converting the binary source into a base64 and put it as the src of the image:

However, this is not acceptable if you load images 'on demand' i.e. when the user

Continue Reading

"The target application has been unloaded" - the annoying error

"The target application has been unloaded" is highlighted by Visual Studio, but doesn't actually do anything. Interestingly enough the error wasn't doing anything. It was just highlighted by Visual Studio and prevented the syntax highlighter as well as the code builder from working. After finding nothing on the internet I gave up and went home.

Continue Reading

Tracing of WCF services - code example

Tracing can be very beneficial especially when the application has already been deployed and we need to figure out why things do work. Useless errors of type HTTP 500 don't give any meaningful results, so I decided to use System.Diagnostics to help me track down the errors. Logging There are two important (and very simplifed

Continue Reading

Using InverseProperty and ForeignKey Attributes

InverseProperty and ForeignKey are (arguably) the most commonly used attribues in Entity Framework when developing in code-first approach. They help greatly simply the job of managing our models. Foreign Key In order to introduce foreign key to our code we need to specify to what objects it maps to. So there are two things that

Continue Reading

Removing Entry from a Database using Entity Framework

Most of the tutorials on the internet seem to focus on how to remove these objects from DataContext as opposed to DbContent. However, if your database is built using code first approach you are unlikely to be using DataContext/. In order to delete an entry from the database, firstly Remove the element and then save

Continue Reading

Proper way of returning multiple values from a method

Since C# 7 you can make method signatures which correspond to multiple values In Python, you can return multiple values from a function. This functionality is not however built-in into C#, shame. I think this is a nice feature of the language. It frequently reduces asymptotic complexity (i.e. "performance") without resorting to implementing another class

Continue Reading

Using #region to improve readability of your Code in VS

#region is an interesting instruction that tells Visual Studio how to wrap the code into 'meaningful' chunks. In larger classes, especially, those with several interfaces it is particularly helpful.

Pretty handy if you ask me. The downside is, and I have seen this already a couple of times, is that some engineers use them

Continue Reading

Returning Http Error as Response in WCF

This is arguably one of the more irritating things in WCF, but as it turns out for good reason. WCF is meant to expose services 'universally' of their endpoint i.e. it shouldn't matter how you connect to the server, the service is independent of the underlying protocol. Therefore, returning HTTP errors from WCF service, well,

Continue Reading

Automated WCF RESTful System Testing with VS

Lately, we've been playing around a lot with WCF. Unit testing WCF services is not exactly challenging (well done Microsoft), but it seems that with unit tests it is quite difficult to test certain behaviour, for example, authentication or authorization. There are other means of developing automated tested system tests, but they are not that

Continue Reading