Visual Studio

Not so long ago I had a small problem with inspecting pretty complex exception. Usually what you see after some exception is thrown is basically this kind of window:


I’ve highlighted Break when this exception type is thrown because without this box being ticked you won’t be able to see $exception pseudovariable inside your Watch window, but about that in a second. After seeing that, usually you click on View Details to check what exactly had happened:


Inspecting all of the provided information doesn’t give you much more information about Exception itself besides the type of it and that there are some more specific information inside the Exception (two exception parameters). Even though we don’t have much information about ‘insides’ of the exception we can tell something from exception name itself, right ? That’s correct, you can figure out what kind of exception or with which group of exceptions you’re dealing with, but you still don’t have specifics. With help comes mentioned earlier $exception pseudovariable.


As you can see there’s a lot information about exception that was thrown. For us the most important part is kept inside ConsoleApplication1.ComplexException:


Now you know exactly what had happened. You can do a little tweak around displaying it in the Watch window, so you won’t be bothered by other properties of Exception object. Just cast $exception to specific Exception type, like so


and voilla

Starting a project with Visual Studio is really easy process. There are just few steps, how many depends on the project template, to get going with new idea. You just go to File -> New -> Project…


then choose the best template that suites your needs, put desired name to it, click OK and you have got yourself a brand new project that is ready to use. You can start coding, right ? There’s always a but, isn’t it ? Yes you can, but you should bear in mind one thing, a project naming convention which determines your project directory tree and has an impact on a C# namespaces.

Examples are the best way to explain a point. I, myself, am a Web Developer so I’ll use a MVC project template as an instance. Let’s create a empty ASP.NET MVC 4 Web Application project and I’ll try to get you through my thinking.

Imagine that we are creating some kind of application for heater company. I’m a little bit cold right now so this is why heaters company, nothing in particular. Let’s say that the company name that we are doing the project for is HeatItUp. They want for themselves a nice website. We already know the first step, File -> New -> Project… and then we choose template and name, easy.


Although project is perfectly fine, in the end the Microsoft shiped the template, you should be aware of the way Visual Studio creates for you project directories. Notice the two input fields for Solution Name and Name (Project Name) in the New Project Window. After creating it like on the above screenshot you will end up with situation like that:



You can see that you’ve got Solution named HeatItUp and Web Application Project (website) named the same way. This is bad from the logic and good practices point of view. Logic, because project named like that does’t say anything to anyone besides you, the creator, about itself. Nobody knows if it is a WPF, WinForms, just a library or as it really is a Web Application unless they open it and look closely. Good practices because of the mentioned above and everything that corelates with it, generated directory tree and namespaces in your code. Little advice, always keep your namespaces clear and tidy because in large projects you can get really confused and even lost when they are poorly designed and when it comes to namespace refactoring…pure evil.

Ok, but even when I made a mistake with the Web Application project name I can easly change it in the Soultion Explorer. Yes, but don’t, because it changes nothing but the *.csproj file name, directories tree and namespaces are still the same. Obviously you can change folder names by yourslef and edit *.csproj file and change RootNamespace tag, refactor all the namespaces and it’s done. Sure, you can, but the price is really high, a lot of effort.


Solution to this issue is just to keep in mind these two input fileds on the New Project window while creating new project, Solution Name and a Name aka Project Name. Or you can do it my way, start with the Blank Soultion


and add systematically projects that you need, always thinking about others who will work, inspect and try to understand the project solution.