Rick van den Bosch - Blog

... on software development, architecture and more

June 2006 - Posts

Unexpected behaviour when calling overriden method
Since not too long ago, I joined the MSDN Forums. The MSDN Forums is a big community where lots of knowledge is passed around. I recommend joining.

Yesterday I ran into an interesting post. It's about an overriding method that exactly seems to match the call, but doesn't get called. In stead, the base method is called... Apparently this is because of override-resolution starting at the base working its way up, and a method declaration that matches more than you would think it does.

You can find the thread here.
Consolas font - my 2 cents

"Consolas is a monospaced font (like an old typewriter) and good for programmers setting code (its core purpose)."

The above quote is taken from the Microsoft Design website, and specifically the part about ClearType fonts. It states the main reason for developing the Consolas Font Pack (download here) is to develop a better font for 'programmers setting code'. Because of this, I primarily tested Consolas in Visual Studio, my editor of choice when writing code ;)

My very first impression of the font was 'Get this out of my editor!'. To be honest, I tried it for the first time at the end of a heavy week, without having optimal ClearType settings. That's pretty important when using a font especially designed to be used with ClearType...
After tuning my ClearType settings (available as an online version and a powertoy download) I tried again and I tried longer, forcing myself to give it a proper chance. After a week I have Consolas installed on both my work and my private machine, and set as the default font in Visual Studio 2003, 2005 and notepad.

I like the Consolas font, because...

  • It is compact, making it possible to display more information in a smaller area
  • Although compact, it's readability is very good
  • It's cleaner (less arches) than for instance Courier New
  • There's a better difference between 'O' and '0'
  • It's closer to my handwriting than any other font ... ;)

The only thing I still have to get used to, is that the lines look like they are pretty close to one another. When there are lots of lines above each other, it tends to seem a bit 'crowded'. Maybe that's just something that takes some getting used to also...

'protected internal' != ('protected' & 'internal')

Having a database management class called DatabaseManager, I wanted to make a property for this DatabaseManager in a BaseForm. This way, every form inheriting from BaseForm would be able to use the same instance of the DatabaseManager.

Because the DatabaseManager exposes functionality to interact with the database, I wanted it to be internal. The property for the DatabaseManager in the BaseForm would have to be internal and protected, so only derived forms would be able to use the property. And exactly there is where I had wrong expectations about what the .Net framework delivers, resulting in the error "Inconsistent accessibility: property type 'x' is less accessible than property 'y'."

Defining a property to be ‘protected internal‘ makes the property visible for internal classes OR classes which inherit from that class. And it’s actually pretty straight forward: the BaseForm was still public (default), making it inheritable for classes outside of the current assembly. Marking a property as ‘protected’ makes sure inheriting classes are able to see that property. And so ‘protected internal’ is protected OR internal, not AND.

When you think about it the solution is as straight forward as the behaviour of the accessibility modifiers. The BaseForm should be internal, and the property should be protected. This way, no one is able to inherit from the BaseForm from outside the assembly. Inside the assembly, only BaseForm-inheriting forms are able to see the DatabaseManager property.

Assess your Microsoft skills

Recently I ran into the Microsoft Skills Assessment page. After singing in with your passport, you can take all kinds of skills assessments for various Microsoft products, from Visual Studio 2005 to Windows Storage Server 2003.

Because I'm looking in to getting an MCPD certification, I was curious about how I would score without even preparing for a test. It's pretty neat to be scoring 80% on the first test I took: Microsoft® Windows®-based Client Development with Microsoft Visual Studio® 2005 and Microsoft Visual C#®. Especially because there were quite some questions about new Visual Studio 2005 functionality that I haven't actually used yet. That's a good stimulant for trying to achieve certification. ;)

If you're thinking about getting certified, or when you're just curious about how your knowledge connects to the different areas of software development (or tools, operating systems etc.), visit the Microsoft Skills Assessment page.

Personal update

Lots of stuff happened the past few months, so it's time for a personal update. Here we go...

  • I'll be attending an MSF4 Agile Masterclass @ Microsoft in July
  • In August my girlfriend and I will be the proud owners of a house in Grasrijk (a part of Eindhoven). We can't wait ... !
  • Because of this, our apartment in Eindhoven is for sale right now (for pictures and info: www.rickje.nl - Dutch)
  • I'm about to release the first version of some generic WebControls I developed
  • The second part of this year we will be giving a Basic training .Net for colleagues again. Maybe this time for colleagues from other locations too!
  • I finally updated my linkedin profile and joined hyves (Dutch)
  • I am currently reading ( recommended ):
    - Agile Software Development, Principles, Patterns, and Practices by Robert C. Martin
    - Applying Domain-Driven Design and Patterns : With Examples in C# and .NET by Jimmy Nilsson
  • I'm participating in a musical (for the third time), which will be performed 14 times in December in De Schalm in Veldhoven (for info: www.veldhovenserevue.nl - Dutch)

That's it for now. At least, if I don't think of anything else soon... ;)

Houston, we have an upgrade...
BloggingAbout.Net was upgraded today! We are now CommunityServer 2.0 enabled. Because of this, I also changed the look and the description of my blog. Why not do everything at once ;)

One little extra piece of information: since the update it is no longer possible to reach a blog by typing in the url bloggingabout.net/username. This has been an extra service since blogginabout.net went to CommunityServer 1.1. Now, whit the upgrade to 2.0, it has been stripped of the feature list. So if you would like to reach a blog, just type bloggingabout.net/blogs/username.
On Risk-based Software Development (and a hint of Madonna)

Last night at eleven thirty, when I was taking a shower after playing volleyball for an hour and a half, I thought of a link between risk-based software development and….. a pop song*. Sometimes you think of stuff at the weirdest moments.

I’m a big fan of risk-based development. By addressing risks first, you are able to prove the feasibility of the project you are doing in an early stage. Also, by defining mitigation and contingency measures you do not only make sure you know how to minimize the chance the risk manifests itself. You know what to do when a risk manifests itself and you reassure the team members and, not unimportant, the constituent.

People tend to push difficult work back. I have to admit it can be more appealing to start out with a highly interesting or fun part of the work that needs to be done, in stead of doing the difficult stuff first. I’ve done that myself in the past. But by doing that you enable Mr. Murphy to come and ruin your project. Especially when his visit occurs in the final phase of your project! If you start out eliminating risks and Mr. Murphy does show up, you have the possibility to inform the constituent about a postponed release in time, get more developers to do the work, let the business make choices as to which features should be cut from the release, and so on. In short: in that case you’re still able to do something about it.

Last night, it was Madonna who pointed it out to me in a single way. Her song ‘Get together’ contains that one sentence that summarises it all: “If it’s bitter at the start, then it’s sweeter in the end.” I think there’s nothing more to be said. It might be it’s not so much fun to start out with, it will payback in the end…

* Whether or not Madonna can be classified as an artist making ‘pop music’ is not the issue here. However, if you would like to discuss this: drop me a line ;)

Error: Could not instantiate activex control 'xxxx-xxx' because the current thread is not in a single threaded apartment

At our current project, we have an application which is deployed using No Touch Deployment. Because of some SEHException we got a few months back, we started our application in a separate thread using a launcher class which contains the Main() method for the application. Recently we added functionality to display HTML pages our application generates, so we added the ActiveX webbrowser (in AxSHDocVw.dll).

Starting an application through IEExec makes that the STAThreadAttribute is ignored. Because of this we received the error "Could not instantiate activex control 'xxxx-xxx' because the current thread is not in a single threaded apartment" as soon as we instantiated the webbrowser. Because we start our application in a seperated thread, the solution was simple: set the ApartmentState of the new thread.

Code:
public static void Main()
{
   
Thread thread;
    ThreadStart threadStart;

    threadStart =
new ThreadStart(StartMyApplication);
    thread =
new Thread(threadStart);

    thread.ApartmentState = ApartmentState.STA;

    thread.Start();
}