Internal Interfaces
Occasionally there is the need to expose, for the purposes of an API or such like, a property of a class that has different external and internal implementations. Consider the code below: a person class with an Id property that is set to -1 by default with an external get property and an internal set property.
public class Person
{
private int _id = -1; // default value
public int Id
{
get { return this._id; }
internal set { this._id = value; }
}
}
If there are several classes that implement the Id property in this manner and there is a need to reference them through a common interface externally then implementing the following on each of the classes should be sufficient:
public interface IIdentifiable
{
int Id { get; }
}
However, to reference these classes internally using the same common interface may be insufficient as it does not allow a call to the internal set property. Clearly it would not be efficient, or necessarily easy, to cast the classes to their individual types prior to making the call. One solution is to use a separate interface for internal operations; an interface with internal scope:
internal interface IIdentifiableInternal : IIdentifiable
{
new int Id { get; set; }
}
Here, we implement the IIdentifiable interface and declare the Id property as new, effectively hiding its IIdentifiable implementation. We don’t reflect this in quite the same manner in our implementation of the IIdentifiableInternal interface on our class though. Instead, we explicitly implement the IIdentifiableInternal interface:
public class Person : IIdentifiableInternal
{
private int _id = -1; // default value
public int Id
{
get { return this._id; }
}
int IIdentifiableInternal.Id
{
get { return this._id; }
set { this._id = value; }
}
}
The external members of the class now include the public get method of the Id property, as does the public IIdentifiable interface. However, internally the class can be referenced using the IIdentifiableInternal interface which allows access to both the get and set methods of the property.
What has been demonstrated is how to take a number of classes with common members that have both public and internal scope and provide a means to reference them through a common interface, both internally and externally.
As a final point, if you have a linked library which you want to have access to the internal interfaces then you can use the following assembly attribute to expose internal to the specified assembly:
[assembly: InternalsVisibleTo("MyLibrary.InterfaceExample")]
Overridden method OnMeasureItem is not being invoked
I just ran into an issue when subclassing the ComboBox class whereby the OnMeasureItem method that I was overriding was not being called. I had set the DrawMode to OwnerDrawFixed in the constructor for my ComboBox which had in turn filtered through to the designer (non-default value). When I amended the value in the constructor to OwnerDrawVariable the change did not then filter through to the designer (no surprises there). The result being that my constructor had the following code:
this.DrawMode = DrawMode.OwnerDrawVariable;
However, this was clearly at odds with the designer as illustrated in the figure below:

In order to stop this occurring again, and to stop any modification of the DrawMode via the designer, I changed the line in the constructor of my ComboBox to reference the base like so:
base.DrawMode = DrawMode.OwnerDrawVariable;
I then added the DrawMode property with the new keyword to replace the base version (see below). You need to include the property setter as the designer will still try to assign a value to DrawMode.
[Browsable(false)]
public new DrawMode DrawMode
{
get { return base.DrawMode; }
set { }
}
After tidying up the designer code everything works like a dream.
Failed to create web application: /Root/RequestHandlerExt
If you are on step 3 of the 172 steps required to install OCS 2007 and feel like banging your head against any wall you can find to relieve the pain then it is not unlikely that you are in the position I have been in all day and have been presented with the following error message during the webcomponents.msi installation against (in my case) Windows Server 2008 and IIS 7:
Failed to create web application. (-2147024809 /Root/RequestHandlerExt )
The log file, which the OCS installer recommends you look at, contains something like this:
WriteMetabaseChanges: Error 0x80070057: failed to create web application: /Root/RequestHandlerExt
Error 26105. Failed to create web application. (-2147024809 /Root/RequestHandlerExt )
MSI (s) (F8!14) [15:33:01:268]: Product: Microsoft Office Communications Server 2007 R2, Web Components Server -- Error 26105. Failed to create web application. (-2147024809 /Root/RequestHandlerExt )
WriteMetabaseChanges: Error 0x80070057: failed to create ASP App
First check that you have the IIS 6.0 compatibility tools installed (see Lee Desmond’s blog for more info). If you have done this and are still getting this error then several sites mention performing an uninstall of OCS, IIS followed by a re-install as a solution.
In my case this was not really an option as I had several websites running on this computer already. It turns out that this was the issue (unsurprisingly, really) and that the installer is looking for the Default Web Site. I performed the migration of site id 1 to a new site and manually revoked the original configuration of the default web site. The install completed successfully after this. I would say to watch out for the IIS7 mmc snap-in and its massive inability to handle renaming of websites with host headers if you’re attempting this yourself and have sites with host headers, obviously.
Welcome to my Blog
Having decided it was time to get myself on the blogging bandwagon I started to look for a blogging engine that would suit my needs. I was initally taken by some of the MSDN blogs provided by Community Server that use the paperclip theme but further investigating led me to BlogEngine.NET, an open source project built on .NET which can only be described as awesome. My choice to go with this piece of software was confirmed when I found a paperclip theme for it provided by Caio Proiete who had taken the time to port it from the orignial. And this is the result. Welcome to my blog.