Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

25 July 2009

Please respect the IDisposable interface

A very frequently asked question about programming on the .NET compact framework is something similar to this:
My compact framework app hangs randomly when it does an HTTP request.

The Compact Framework only allows three simultaneous requests. The fourth request will have to wait until one of the other request objects is disposed. If you have time-outs or a request that blocks the application endlessly, you probably forgot to dispose the previous requests.

The solution is therefore quite simple. The GetRequestStream() and GetResponseStream() methods both return Stream objects. The Stream class implements the IDisposable interface. And, if you notice an IDisposable implementation, you should use it.
You may be lucky with a fast garbage collection, but in most cases, you won't. So, IDisposable? Please Dispose().

If you can correct the error in your own code, you are lucky. But too often I had to dig into sources of other libraries, which did not respect IDisposable implementations, let alone use it. In the case of a request or response stream, this is quite a flaw and renders the library useless for the Compact Framework.

I think libraries / frameworks should respect IDisposable interfaces when they meet one. And use them instead of blindly ignoring it. This will save a lot of people a lot of headaches.

24 July 2009

Compile a thrift api in C#

Evernote has an API in thrift. To use this api in C#, you need a thrift compiler for windows to compile the thrift files into C# generated code.

The thrift compiler has to be compiled itself, there is no binary download. Worse, you need Cygwin to compile the compiler.

- Download the Cygwin installer
- Click through to the list of components. Sort the list alphabetically and select all libraries that resemble the libraries needed summed up on the ThriftInstallationWin32 page of the thrift wiki.
- download the thrift source from the "Download the snapshot" link on the Apache Thrift download site.
- copy the thrift directory to a new dir c:\cygwin\data
- start cygwin, cd to /data/thrift

Do what's mentioned on the wiki page:
- enter the command "./bootstrap.sh"
- enter the command "./configure"
- cd to compiler/cpp
- enter the command "make"
- after the command finishes, there should be a thrift.exe in this directory.

For your and my future convenience, download the thrift.exe file here.

- download the thrift files to compile. In my case, the evernote zip file containing the thrift definition files at http://www.evernote.com/about/developer/api/
- find out you had better done that as your first step, because the zip file already contains the generated code files. Well, it was a nice exercise anyway.
- just to make myself believe that it was not entirely useless, compile the thrift files:
./thrift.exe --gen csharp evernote/NoteStore.thrift

the output can be found in the subdirectory gen-csharp.

13 July 2009

NHibernate and the annoying log4net dependency

A patch

NHibernate has always used log4net as logging library. If you wanted to use a different logging mechanism you couldn't. Fortunately a thin abstraction layer exists, .NET Common.Logging, which much resembles the log4net interface. Common.Logging can be configured to use NLog, log4net, EntLib or a custom built-in lightweight logging.

I created a patch for the 3.0 trunk. The patch contains all changes needed to remove the dependency on log4net and replace it with a dependency on Common.Logging.

The patch files can be downloaded from this location.

The binary files are included in the zip file:
  • lib\net\3.5
    • Common.Logging.dll (updated to 2.0)
    • Common.Logging.*.dll (several logging implementations)
    • Common.Logging.Extension.dll (for unit testing, an in-memory logging implementation)

I upgraded the unit-tests as well. There had to be a few changes:
  • Some of the tests test logging. Because of this, logging had to be moved to an in-memory logger (Common.Logging does not have appender functionality). Because of this, logging that is done by the unit tests itself about the results of unit tests, won't be logged to a logfile. If this is still needed, another mechanism for this has to be found.
  • Some unit tests are not applicable in my situation (SQL Server 2005). I did not test them.
  • Two unit tests now fail on purpose. This might be a bug: the mapping document is invalid, but there is no error thrown when LogLevel != Debug. The tests used to succeed because the loglevelwas other than Debug, but I changed that. Somebody should look into those. See NHibernate.Test.MappingTest.NonReflectiveBinderFixture and NHibernate.Test.NHSpecificTest.NH712.Fixture
At this moment the new logging mechanism makes a breaking change. The config should be updated so it will configure Common.Logging. I included a test project with settings for NLog, Log4Net and the built-in console logger.

You can follow this issue at the NHibernate Jira, issue 1554

10 July 2009


Op de website van het gebarencentrum staat een uitgebreide woordenlijst met filmpjes van gebaren uit de nederlandse gebarentaal. Omdat wij zelf proberen onze "baby's" (0 en 2) wat babygebaren bij te brengen, maken we veel gebruik van de zoekfunctie. Die werkt helaas niet zo handig. Het gebarencentrum werkt gelukkig aan verbetering. In de tussentijd voorziet het programma "Gebaren" in een alternatieve zoekfunctie voor de website.

De inhoud van het programma Gebaren is volledig afkomstig van Het Gebarencentrum. Alle filmpjes enuitleg kunnen ook op deze website bekeken worden. Voor volledige functionaliteit, zoals grammatica, subsets van het woordenboek, enalgemene achtergronden, zie de website www.gebarencentrum.nl


Het programma "Gebaren" kun je op een WindowsXP / Vista computer installeren. Je computer moet wel minimaal het .NET framework versie 3.5 geinstalleerd hebben en een recente versie van Windows Media Player. Je merkt het vanzelf als je die nog moet installeren: als .NET 3.5 ontbreekt geeft de installatie een foutmelding, en als Windows Media Player geupdate moet worden, zie je dat aan het ontbreken van de filmpjes nadat je een woord hebt gezocht.

Als je het programma hebt geïnstalleerd, kun je over het gebruik van het programma lezen in de handleiding. Raadpleeg de handleiding via het "Help" menu.

Twee dingen die niet aanstonds duidelijk zijn:

  1. Zoek met een Hoofdletter om niet een deel van het woord te zoeken, maar alleen woorden die beginnen met de ingetypte term.

  2. De eerste keer dat je het programma opstart, duurt het even voordat je kunt zoeken, omdat hij de lijst met woorden van de website moet downloaden.

06 July 2009

InternalsVisibleTo attribute how-to

I tried avoiding the InternalsVisibleTo attribute for our testsprojects, simply because I didn't know how it works or how I could get it to work.

But that is not a very convincing reason not to use it. So for future reference:

1. Sign the test project with your keyfile

2. navigate to the test assembly with a visual studio command prompt and get the output of this command:
sn.exe -Tp <assembly>

3. Attach the parts of the public key together to form one long string of characters, and create an attribute in the target assembly:
InternalsVisibleTo("Assembly.Name.Here, PublicKey=00240000048.....")