.NET, Universe and Everything according to Dirk

We apologize for the inconvenience

I upgraded an ASP.NET MVC2-based web application from autofac 1.4.4 to autofac 2.2.4 today.  I hoped that simply swapping out the dlls would be enough, but that was not the case.  I found the help I needed on these pages:

Everything worked again after applying the information from those pages.

Update 2010-08-22: I needed http://code.google.com/p/autofac/wiki/WcfIntegration as well, since there have been changes to the WCF integration.


TechTalk (the company I work for) is organizing a "Certified Scrum Developer" course.  The purpose of the course is to teach you (or reinforce your knowledge of) the way software development can be done in a scrum environment.  Successful completion of the course can be applied towards the Certified Scrum Developer credential that was recently introduced by the Scrum Alliance.  The course will be held from 13-15 October 2010, by TechTalk at Microsoft Austria's Microsoft Innovation Center.

The tentative schedule allows for large chunk of Test Driven Development-related content on day 2, and I am deeply involved in the preparation of that part.  I hope you'll attend to enjoy the fruits of my work :-)


Shameless Plug 1: DevCamp 2010

TechTalk (the company I work for) is once again part of the organization of DevCamp - the 4th edition already.  DevCamp is an Austrian developer conference held yearly in October in Vienna.  This year's edition will take place on tuesday 12 October 2010, at Vienna Marriott, Parkring 12a, 1010 Wien.  There will be three tracks: Windows Azure – Über oder in der Wolke?, Application Lifecycle Management and User Experience & Applications.


Troubleshooting SQL Server CE 3.5

If SQL Server CE 3.5 mysteriously cannot be found by an application anymore - even if another one is perfectly able to load it - with this exception message: Cannot open “X:Pathtodatafiledatafile.sdf”. Provider ‘System.Data.SqlServerCe.3.5′ not installed then you might try the solution suggested at http://www.geekfreeq.com/linq-sql-server-ce-35/.  It worked for me.


Here's a technique for creating a pencil drawing from a photograph using Photoshop - my wife grabbed it from the internet, modified it a bit and wrote it down as a recipe that's understandable to non-photoshop-wizards like me.  Here goes:

  1. Photo so viel als nötig croppen (erspart einiges an wegradier-arbeit)
  2. Layer from Background
  3. alles was nicht dabei sein soll, mit dem eraser-tool wegradieren
  4. Desaturate
  5. desaturierten layer kopieren
  6. invert: strg i
  7. blending mode: color dodge: alles wird weiß
  8. filter – blur – gaussian blur
  9. eventuell noch korrekturen
  10. als .psd speichern
  11. Old parchment 3 öffnen (that's the background image where the pencil drawings where used on.)
  12. Place bearbeitetes Foto
  13. Blending mode: ausprobieren
  14. wenn zu hell: image- adjustment – shadow/highlight oder variations
  15. wenn linien von bearbeitetem Foto zu dunkel hilft statt radieren im original auch Layer style „outer glow“ 

Some more design tips

Some more interesting design resources as a note to self: http://speckyboy.com/2009/11/02/40-fresh-and-free-icon-sets-for-web-designers-and-bloggers/.


<label for=?textbox? /> in WPF

From a usability point of view, it is a good thing to be able to associate labels and entry fields with each other: a screen reader knows which label belongs to the entry field, and if the label has a shortcut, pressing the shortcut typically results in the entry field receiving keyboard focus.

In HTML, this is done using the ?for? attribute of the label. In Windows Forms, this is done by cleverly arranging the tab order for the controls.  In WPF, this can be done by binding the Target property of the Label to the entry field:

<Label Target="{Binding ElementName=startEntry}" Content="_My Label:" />
<TextBox x:Name="startEntry" />

Note: I am writing about ?Windows Mobile? as in ?based on Windows CE 5.x? rather than ?Windows Phones? as in ?based on Windows CE 6.x?.

Test-Driven Development

It came as a surprise to me ? a welcome one, to be sure, but a surprise all the same ? that there actually is a Unit Test framework for the .NET Compact Framework that is both easy to use and really runs on the .NET Compact Framework.  It is called MsTest ? Unit Testing for .Net Compact Framework is now friendly enough! describes how to use it.

Debugging Unit Tests on .NET CF is said to be a pain (at least according to Debugging Smart Device MSTEST Unit Tests). My team and I are of the opinion however that if things come to the point where you need to debug a unit test, you are doing something wrong.  So we decided to accept this problem.

There?s one pitfall there though.  Every Smart Device project in Visual Studio has an associated target device.  However, the unit tests do not run on the associated target device of the test projects.  They run on the target device of the test configuration instead.

SmartDeviceTestRunConfig

What?s with the Network?

Enabling network on a Windows Mobile Device is simply a matter of running the emulator, pointing to File ?> Configure on the emulator, clicking on the Network tab and making sure that the NE2000 checkbox is activated.

MobileNetwork

However, on Windows 7 you may receive the following error when you try to enable the checkbox and click on OK: ?The required Virtual Machine Network Driver could not be found. Make sure that Virtual PC 2007 is installed. You can install Virtual PC 2007 from  http://go.microsoft.com/fwlink/?linkid=46859?.

This is a bit of a quandary: Virtual PC 2007 does not work on Windows 7, there is a separate ?Virtual PC for Window 7? (part of Windows XP Mode on Windows 7).  In order to enable networking on the emulator, you need to install Virtual PC 2007.  That results in Virtual PC for Windows 7 being broken (at least the network).  So if you need Virtual PC on Windows 7, you need to uninstall Virtual PC 2007.

Fortunately, it is possible to install the network components of Virtual PC 2007 only, so you can have the best of both worlds: working network on the device emulator, and working Virtual PC on Windows 7.  Windows Virtual PC and the Microsoft Device Emulator describes how to set this up.

ActiveSync, USB and DMA Connections

In order to connect a Windows Mobile device to your PC, you need ActiveSync on Windows XP and Windows Mobile Device Center on Windows Vista or 7.  If you want to connect a Windows Mobile Emulator to your PC as well, you will need to allow DMA connections.

connectionSettings

Once you have allowed DNA connections, you need to ?cradle? your emulator, using the Device Emulator Manager (%ProgramFiles%\Microsoft Device Emulator\1.0\dvcemumanager.exe).  Your emulator will then behave exactly like a physical device connected to your PC.

cradle

/etc/hosts

Sooner or later during development of any non-trivial project there comes the need to match DNS names to IP addresses. In other words, you need a hosts file.  Too bad that there is no hosts file on Windows Mobile.

As it turns out, you can achieve the same goal by using the registry of the mobile device, as described in /etc/hosts file equivalent in Windows Mobile device.

Remotely Controlling a Windows Mobile Device

It is much more comfortable to control a device by using the keyboard and mouse of your own PC than to use a stylus and tap around on small squares. Additionally, it comes in handy if you can copy text on your pc and paste it on the mobile device, or vice versa.  MyMobiler is a freeware program that does exactly that; SOTI Pocket Controller is a commercial alternative.


TDD Master Class with Roy Osherove

Last week, I took part in Roy Osherove's TDD Master Class in Vienna. The name "Master Class" is thoroughly appropriate: the 5 days are packed with loads of useful advice, best practices (including what will go happen if you don't follow them), concise theory and lots of exercises.  The exercises are pair programming sessions, and Roy occasionally looks over your shoulder and gives helpful advice or asks annoying (*) questions like "is this the simples thing you can think of?".

(*) annoying as in "he's right and I'm probably wrong".

Some things I learned (the top two for each day):

  • Think like the laziest developer in the world
  • Beware of the serial killer
  • TDD Kata
  • The difference between stubs and mocks
  • A feel for the API differences between Rhino Mocks, Moq and Typemock Isolator
  • When to use an isolation framework and when not
  • The three pillars of trustworthy unit test
  • How to review unit tests
  • Dealing with legacy code
  • Object Oriented Design and Testable Design are sometimes at odds with each others

Honorable mentions go to the recurring topic of using Visual Studio without a mouse.

Roy is both very knowledgeable and very down to earth - a good combination in a teacher. I wholeheartedly recommend his master class. Do yourself a favor and make sure you have some experience with unit testing before you attend the course, otherwise you will find the master class rather overwhelming and will miss many of the nuances.

I'll finish with Roy's and mine favorite quote by Arthur C. Clarke (slightly adapted): Any sufficiently advanced unit test is indistinguishable from magic.


Random - For a Given Value of Random

I had some fun with .NET's random number generator (System.Random) last week. In my defense, I want to point out that

  1. I do know that System.Random is not a true random number generator, but rather an algorithm that "fulfills certain statistical properties" of randomness.
  2. I do know that if two instances have the same seed, then they will produce the same series of random numbers.
  3. I do know that if you instantiate an instance of System.Random using the default constructor, the seed is taken from the current time of the computer.

What I did not fully realize until last week was that the length of a clock tick is 100 nanoseconds (0.1 microsecond). So creating 5 instances of System.Random in a row may (and did) happen in the course of a single clock tick - resulting in 5 identical random number series. Very random indeed.

The MSDN documentation of System.Random actually mentions this problem (and its solution), but hey, who reads the manual?