Category «C#»

async and await in C# 5

C# 5 comes with just a few new features and async is arguably the more important of those. I have started looking into it a couple of days ago and I thought I would share my thoughts on it here. Asynchronous programming was touted was the next big thing for quite some time, but it …

What I miss about C#

It has been a month or so since I started programming in C++. To be frank it is not the monster that I thought it would be and it wasn’t that hard to move to C++ from C#. Granted I haven’t faced any of the notorious and nasty bugs that is difficult to debug in …

Duck Typing using C# 4.0

using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { QuackTheQuacker(new Toy()); QuackTheQuacker(new Duck()); } static void QuackTheQuacker(dynamic quacker) { quacker.Quack(); } } class Toy { public void Quack() { Console.WriteLine("A toy that quacks"); } } class Duck { public void Quack() { Console.WriteLine("A duck that quacks"); } } }

Getting Access Denied Errors in your WCF service or ASP.NET application ?

We are using impersonation in our WCF Service so that credentials of the user can flow to the backend layer (where authorization is done). Strangely we were getting Access Denied errors when the client tries to connect to the service. The error message was like: Could not load file or assembly ‘MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ …

Covariance in Arrays

The following code throws an ArrayTypeMismatchException. I was never aware of this until today. Here is the reason for this behaviour. On a related note, Generics catches this problem at compile time. Click here to get code that you can copy-paste.