A few weeks back I blogged about Unit testing event handlers using InternalsVisibleTo. Today I run across a, to put it mild, annoying problem that took far to long to solve. The project I'm working on has come to a point where the user interface has to go through a metamorphoses. I'm redoing the application in full WPF (for speed and convenience I will keep a hosted property grid, but that's another story).
When added a user control to the application I started to get intermittent errors. I mix the development with Blend and Visual Studio 2005. It would always build in both environments but from time to time I kept getting these pesky exceptions. This went on for quite some time. As it started when I introduced the custom controls I began my quest there. I recreated the controls and it worked for a while an the it returned. This was driving me crazy. The exception looks like this:
Could not load file or assembly '...., Version=...., Culture=neutral, PublicKeyToken=......' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Error in markup file '....;component/Window.xaml' Line 2 Position 5.
It usually worked when I removed all for a full rebuild but not always and sometimes a restart seemed to do the trick. But not always, and there is no way to work like that. I was ready to give up when I remembered a similar hard to track down problem. There is some kind of snag or bug a bug when you sign the assembly and at the same time leave the assembly version in the assembly info to automatic increment. For example, the value:
[assembly: AssemblyVersion("1.0.0.*")]
will give you a terrible headache. So make sure you set this to a constant value when you sign your assemblies. Something like this should work:
[assembly: AssemblyVersion("1.0.0.0")]
I hope I at least saved someone a few hours of frustration.