Load vs. Get in NHibernate

I really like the lazy-loading feature of NHibernate, because it can dramatically reduced unneeded traffic to your database.

But I had a hard time figuring out, why I could not distinguish whether an object exists in the database or not. Because of the way lazy-loading works, you always get an object returned by the load method. Usually this will be a proxy object. If you try to access a property of an non-existing entity (on the proxy), you well get an exception, but I would rather know this a time ahead.

Well, this is where the get method comes into play. This methode retrieves the values of the properties of an entity directly, instead of lazy-loading these values by using a proxy-object like the load method does.

WCF: using Interfaces in Operation Contracts

WCF (Windows Communication Foundation) is a great think. If you ever though supplying and consuming web-services with .Net 1.1 & .Net 2.0 was easy – think again! WCF goes a long way to even reduce the burden of this process!

OK, so you’re all excited about using WCF and setup your service-contract by defining an interface like this:

[ServiceContract]
public interface IReviewService
{
[OperationContract(IsOneWay=true)]
void InitiateReview(IReviewTrigger reviewTrigger, IDocument reviewDocument);
}

As you can see, I used interfaces as ther parameters for my operation-contract. Within the application I’ve a concrete implementation of the IReviewTrigger as well as the IDocument interfaces, So now you go ahead and consume your service in an application like this:

ChannelFactory<IReviewService> factory = new
ChannelFactory<IReviewService>("WorkflowDmsReviewServiceEndPoint");
IReviewService myService = factory.CreateChannel();
ReviewTrigger myTrigger = new ReviewTrigger();
Document myDocument = new Document();
myService.InitiateReview(myTrigger, myDocument);

But this is a booboo. You will get an exception from the service-host, that an object of type ReviewTrigger was not expected. Well, what should I say – the contract defined IReviewTrigger instead of ReviewTrigger. I would consider this to be a shortcomming of WCF … but who is asking me!!

Well, after struggeling with this for quite some time (and being stubborn not to use the concrete class in my operation-contract!) I found a solution. Aaron Skonnard blogged about using a NetDataContractSerializer instead of the built-in serializer … and all over sudden this works!!

Follow-Up: I finally did give up on passing complex types (objects) to operation contracts; instead I’m only passing the primary key of my object to the operation contract. This is reducing the overall overhead and eliminates the necessarity of the NetDataContractSerializer. I just read my Trigger and Document from the above example from my data-layer instead.

Trillian & Miranda – a story of two ICQ Messangers

I’ve been using Miranda for quite some time now, and try always to stick with the lastest releases.

The last release is Miranda IM v0.8.0 Build #3. Unfortunatly there seem to bee some issues concerning the ICQ protocol:

  • communication with Trillian does not work anymore
  • contacts seem to be offline, even though they are online

The first issue can be solved using a previous version if the icq.dll. Version 0.3.10.6 seems to be fine. It seems that Trillian can not handle the new message format, which was introduced to Miranda to improve the compatibility with ICQ 6.

The other issue is more severe. AOL seems to have changed something regarding communication with unauthorized contacts … there has been already some discussion at the Miranda Forum.

Extending the Command Prompt

OK, you know all about pimping your Windows, but there is this one piece, that has never been touched bevor: the command prompt!

Well, guess what? There is more to it! When looking at the properties of the prompt you might be tempted to change the font of the command prompt, only to find out, that only one TTF is actually available: Lucida Console

This is because, there is – what else could there be!! – a registry-key controlling which fonts are valid for the command prompt. Looking at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont reveals that only Lucida Console is actually available. So just add another font to the key by adding an extra zero to the name. I added 00=Envy Code R 🙂

Another option is to use a replacement for the plain-old-command-prompt … like Console or PowerCmd.

Customizing the appearance of Visual Studio

Well, Visual Studio comes quite boring to you. Especially customizing the use of colors and fonts greatly enhances the use of Visual Studio.

I recently came across some sites, that offer some nifty stuff you might need to pimp you appearance of Visual Studio:

  • Fonts
  • pre-configured vssettings-files

Fonts

One font I just stumbled across is Envy Code R by Damien. This font is just awesome, and I personally like it much better than Consolas (not to mention Courier New, which is out of the question by now!!).

vssettings

Besides a nice and appealing font you also might want to tweak the color-coding of visual studio; preconfigured vssettings might ease this step.

Thomas Winterdom has a nice collection of Visual Studio Color schemes.

IntelliSense for NHibernate

It seems like quite a few frameworks seem to be missing the intellisense support out of the box – tis is very unfortunate.

Just like the Windows Communication Foundation NHibernate seems to be missing intellisense as well. But there is hope!

You basically need the NHibernate schema definitions (nhibernate-configuration-2.0.xsd, nhibernate-mapping-2.0.xsd and nhibernate-generic.xsd) and copy them into the Visual Studio “schemas” directory (the default path is C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas).

At last you might want to restart your Visual Studio.

IntelliSense for Windows Communication Foundation

A great improvement of Visual Studio 2005 compared to the 2003 edition is the intellisense for configuration-files. Especially complex configurations like windows communication foundation (WCF) can greatly benefit.

Unfortunatly Microsoft did not include any schema-information with the .Net 3.0 Release, so intellisense is not available out of the box. This will probably only be available with Visual Studio 2008 (Orcas) which is being release right now. But for those of you, who want to add the intellisense also to VS 2005, you might want to install the latest CTP for Visual Studio 2005 extensions for .NET Framework 3.0 (WCF & WPF). This also adds some missing developer features such as ”svcutil.exe” to generate client-proxies for the WCF.

Activating the Sharepoint Publishing Infrastructure

I just stumbled across the need to activate the Publishing Infrastructure feature of MOSS, so I can assign Master-Pages to websites. But unfortunately my attempts where discarded by an “access denied” message.

I found a great article describing on how to work around this problem – although I would have loved to know why this error occurs and what the Microsoft-way to avoid this problem would be …

Nerds – step forward please!

For those of you, who just do programming for the heck of it – this is nothing new to you. For everyone else: there are certain programming languages that don’t make any common sense!

Well, probably every one has come across some code, that was to certain means unreadable. Sometimes this is not intended, other times it’s fully intentionally. Perl offers a whole lot of potential to write unreadable code, since you have quite a few “shortcuts” to variables and you can just stuff everything in one line.

This little fellow is just one nice example:

sub b{[@b=(abs||No,bottle."s"x!!++$_,of,beer),on,the,wall]}print "@{+b}.\n@b,\nTake one down, pass it around,\n@{+b}.\n" for-pop||-99..-1

So, did you recognize it – or did you try it?

For those of you, whom Perl is not offering enough – you might want to try some other languages. While it only takes a couple of seconds to write a programm to add two numbers using C or perl, you can spend a couple of hours accomplishing the same with INTERCAL. Or for example Whitespace, this language only uses Space, Tabs and LineFeeds, so all of which are non-visible characters!

I’ve listed some of them:

Fixing Performance Counters

I use the Process-Explorer from Sysinternals (now part of Microsoft) to watch my running processes. Some day I noticed that .Net processes are not highlighted anymore, like they were before.

So doing some google-research I came across a post at the systinternals forum. I figured that I was missing all of my performance-counters, that was the reason why .Net processes where not highlighted anymore. Looking at the performance-monitor also revealed, that all performance-counters where just “numbers” and had no measures associated with them.

So I followed the steps descriped in the knowlegde-base article 300956. Although this article states it’s for Windows 2000 only, this did work with my german version of Windows XP SP2 as well.

After fullfilling the steps of the article I also re-registered the performance-counters of .Net 1.1 as well as .Net 2.0 by loading the counters from the *.ini files from C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 and C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.

After restarting process-explorer my .Net processes showed up highlight like they did before.