Saturday, December 06, 2008

TeamBuild Error Running UnitTests with WPF Objects

I’m just wrapping up sprint 1 of my latest project and as such have been taking care of some infrastructure type tasks. We’re using TFS2008 for our SCM/CI stuff, so I created a new build definition for our main project (WPF/Linq to SQL). We had about a dozen unit tests at this point, all of which we green on our machines (Works on my machine), but once I fired off my build on the CI box, two of the tests failed with the following error:

Test method TestAssembly.TestClass.MyTest threw exception: System.Windows.Markup.XamlParseException: 'StackPanel' object cannot be added to 'Grid'. The program issued a command but the command length is incorrect. (Exception from HRESULT: 0x80070018) Error at object 'System.Windows.Controls.StackPanel' in markup file 'TestApp.UserInterface;component/view/myview.xaml'. ---> System.Runtime.InteropServices.COMException: The program issued a command but the command length is incorrect. (Exception from HRESULT: 0x80070018).

The two tests that failed happened to be the two that created an instance of a WPF Window, which no other tests in the suite did, so at least we had some clues to Google with. It didn’t take long to stumble across this page: MS Forums: .NET 3.5 SP1 breaks use of WPF under IIS.

Although we weren’t doing anything with IIS, the rest of the symptoms sounded exactly like what we were dealing with. We took the advice given in the first community comment that indicated we should run the executable in XP SP2 compatibility mode and applied that the the TFSBuildService executable. The next build succeeded and we were back to coding.

The good news is that MS intends to fix this issue with a future patch/service pack, but not until sometime next year, so for now, you’re stuck with forcing compatibility mode on your failing executables.

No comments:

Post a Comment