C#

Difference between readonly and const in C#

Recently I was asked what the difference was between readonly and const in C#, and I couldn’t really tell the exact difference. There are several good articles about this, like this StackOverflow article. In this article, I’ll stick to the very basics.

Continue reading

Advertisements
C#

New features in C# 6.0

With the release of Visual Studio 2015 last week, I thought it would be a good time to inspect the new features that come with the newest version of C#. Although C# 6.0 is certainly not a major release from a developer’s perspective, there are some items that every developer will use in the coming years. In this post, I’ll show some examples on how to use these new features.

Continue reading

C#, Entity Framework

How to automatically load navigation properties in Entity Framework

Anyone who has worked with Entity Framework will have had to manage with loading related entities. I believe many developers will agree the way that system works is difficult to reconcile with design patterns such as the Repository pattern. In this post, I’ll provide one quick and easy way to automatically load all related properties from the database.

Continue reading

MVC, Troubleshooting

ASP.NET MVC fixing error ‘Multiple types were found that match the controller named’ when routing is not the problem

I just came across following error message while I was converting one of my ASP.NET MVC applications:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
hbulens.WebUI.POC.Controllers.HomeController
hbulens.POC.WebUI.HomeController

Beschrijving: Er is een onverwerkte uitzondering opgetreden tijdens het uitvoeren van de huidige webaanvraag. Raadpleeg de stacktracering voor meer informatie over deze fout en de oorsprong ervan in de code.

Details van uitzondering: System.InvalidOperationException: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
hbulens.WebUI.POC.Controllers.HomeController
hbulens.POC.WebUI.HomeController

Normally, you would expect something is wrong with the routing engine, The error messages on this subject are quite clear:

[InvalidOperationException: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

In my case, this wasn’t the problem. Instead, I changed the namespaces and assembly name of my MVC project from hbulens.WebUI.POC to hbulens.POC.WebUI, but the ASP.NET MVC project itself remained intact.

Being uncautious, I left the old assembly output in the bin folder while I was trying to debug the new assembly output, with beforementioned error as a result.

There is a very easy way to fix this: delete your bin folder and rebuild your project.

C#

How to prepare for Microsoft exam 70-483 programming in C#

Today I passed the 70-483 Programming in C# exam. As any other Microsoft exam, the passing score is 700 on a total score of 1000. I scored way above my expectations, so I’m very happy that my efforts are rewarded with a MCP certificate. I can highly recommended experienced consultants and developers to take this exam. For beginning programmers ( < 1 year) this exam will probably be too difficult as there are many topics in scope of the exam.

In order to motivate anyone who wants to take this exam, here is how I experienced the exam.

Continue reading