August 2012 - Posts

Type ‘InArgument(mtbwa:BuildSettings)’ of property ‘BuildSettings’ errors in TFS 2012 RTM builds
Thu, Aug 30 2012 9:30

I posted a while ago that you saw errors when trying to edit TFS 2012RC build process templates in VS 2012RC if the Visual Studio class library project you were using to manage the process template editing was targeting .NET 4.5, it needed to be 4.0. Well with Visual Studio 2012 RTM this is no longer the case, in fact it is the other way around.

I have recently upgraded our TFS 2012 RC –> RTM and I today came to edit one of our build process templates (using the standard method to edit a process template with custom activities) and got the following error when I tried to open the XAML process template for editing

System.Xaml.XamlException: 'The type ‘InArgument(mtbwa:BuildSettings)’ of property ‘BuildSettings’ could not be resolved.' Line number '3' and line position '38'.

 

image

At first I assumed it was my custom activities, so I tried editing the DefaultTemplate.11.1.xaml in the same manner, but got the same problem.

Strangely I found that if I had no solution open in Visual Studio then I could just double click on the DefaultTemplate.11.1.xaml file in Source Control Explorer and it opened without error. However, if I had a solution open in the same instance of VS2012 that contained a class library project that linked to the same XAML file I got the error. Unloading the project within the solution allowed me to open the file via Source Control Explorer, reloading the project again stopped it loading.

So it all pointed to something about the containing class library project stopping referenced assemblies loading. On checking the project properties I saw that it was targeting .NET 4.0 (as required for the RC), as soon as I changed this to .NET 4.5 it was able to load all the required Team Foundation assemblies and I was able to edit both the default template and my custom build process template.

Two bits of good news – DDDNorth and Raspberry PI
Tue, Aug 28 2012 8:06

The registration has opened for DDDNorth 2 (In Bradford) where I will be speaking on Unit testing in VS2012

Also my Raspberry PI has just arrived – after only 6 months of waiting, but I don’t think I can work it into my DDDNorth session

Getting Typemock Isolator running within a TFS 2012 build – part 2
Fri, Aug 24 2012 9:05

I posted previously on getting Typemock 7.x running in a TFS 2012 RC build process . Well it seems the activities I previously published did not work on the TFS 2012 RTM build i.e if you do nothing other than upgrade your TFS server from RC to RTM a previously working build fails, no attempt was made to run any tests and I got the unhelpful error

TF900546: An unexpected error occurred while running the RunTests activity: 'Executor process exited.'.

Note: TF900546 seems to be the generic – test failed error number. If you see it you will usually have to look elsewhere for anything helpful.

So I assumed that the problem must be some difference with the TeamFoundation assemblies I was referencing between the RC and RTM versions, so I rebuilt my activities, all to no effect, I got the same error. So I did some more digging into the code. I found a number of issues, why these had not caused an issue before I don’t know:

Target property

If you do not specify a .NET version via the Target property of the TypeMockRegister activity it does not attempt to start interception. As setting this property every time you want to use the activity is a pain, I modified the activity so that if no Target property is passed then the value v4.0.30319 is used, the version of .NET 4.5 as it appears in the c:\windows\Microsoft.Net\framework folder.

Note Missing of the leading v if the Target value causes the TFS build agent to hang, I have no idea why.

Once this change was made the build ran and it tried to run all my tests, but the ones involving Typemock failed, with the message

Test method BuildProcessValidation.Tests.MSTestTypemockTests.DirtyTrickMockingWithTypemock_Email_is_sent_when_client_order_is_processed threw exception:
System.TypeInitializationException: The type initializer for 'f5' threw an exception. ---> System.TypeInitializationException: The type initializer for 'TypeMock.InterceptorsWrapper' threw an exception. ---> TypeMock.TypeMockException:
*** Typemock Isolator needs to be linked with Coverage Tool to run, to enable do one of the following:
   1. link the Coverage tool through the Typemock Isolator Configuration
   2. run tests via TMockRunner.exe -link
   3. use TypeMockStart tasks for MSBuild or NAnt with Link
For more information consult the documentation (see Code Coverage with Typemock Isolator topic)

On looking in the build box’s event log I saw the message

.NET Runtime version 4.0.30319.17929 - Loading profiler failed during CoCreateInstance.  Profiler CLSID: '{B146457E-9AED-4624-B1E5-968D274416EC}'.  HRESULT: 0x8007007e.  Process ID (decimal): 2068.  Message ID: [0x2504].

AutoDeployment

Basically the issue was the Typemock interceptor, the profiler, was not being started because Typemock was not installed on the build box. To prove this I manually installed Typemock on the build box and the error went away, all my tests ran. So happy my activity basically worked, I removed Typemock from the build box and the problem returned, so I know I had an autodeployment issue.

On checking the activity code again I found I was not handling the nullable boolean correctly for the AutoDeploy build argument of the type TypemockSettings. As soon as this was fixed and deployed by build leapt into life.

In summary

So I am please to say I have a working activity again, as I said in my previous post I see this as stopgap measure until Typemock Release their official version. This set of activities have had minimal testing and I am not sure the undeploy logic is working fully, but as I don’t need this feature I am not worrying about it for now.

Hope you find it useful in its current state.

Experiences upgrading our TFS2012RC to RTM
Mon, Aug 20 2012 6:56

We have just completed the upgraded of our TFS2012 server from RC to RTM. All went smoothly, just a few comments worth mentioning

  • The install of TFS2012 (after the removal of the RC) required three reboots, 2 for C++ components and one for .NET 4.5. So  if seeing reboots don’t worry too much.
  • When running the upgrade wizard we got a verify warning over port 443 already being used (we had manually configured via IIS manager for our server to use 8080 and 443). We ignored this warning. However after the upgrade wizard had completed, with no errors, we found that the new web server could not start. Turns out it it had been left bound as HTTP to Port 443, so it was very confused. We just deleted this binding and re-added HTTP on 8080 and HTTPS on 433 with our wildcard certificate and it was fine. So in hindsight we should have headed the warning and removed our custom bindings.

So now off to the long job of upgrading build box, test controller and the rest.

Weekend trip to see family – 1 OS upgrade, 1 network printer installed and 3 machines de-virused
Mon, Aug 20 2012 5:48

I have been away over the weekend seeing family, and as anyone who is in IT (or is a medical doctor I suspect) would expect I had the standard experience – everyone wanted me to show me something they were worried about that turned to be virus related. This trip I did one operating system upgrade, one network printer installation and de-virused three PCs. So nothing out of ordinary.

The one thing I would mention was how useful I found the contents of Mark Russinovich’s TechEd Session ‘Malware Hunting with the Sysinterals Tools’. This saved me the complete machine rebuild I had feared for one PC which had got infected with a bit of poor quality ransomware  that turns out to only be a splash screen that I could easily spot with Autoruns from the Sysinternals Suite. The video is well worth a watch for all of user in the family IT support game.

A move to Windows 8 RTM (and VS2012 RTM), not too painful
Thu, Aug 16 2012 10:45

First I thought I could do an in-place upgrade of my Windows 8RC PC, turns out you can’t (not sure if it would have been wise anyway) so it was format disk time.

I had hoped for a seamless install of Windows 8, but it hung after detecting devices. It seems it was the ‘old problem’ down to Lenovo/Nvidia Optimus graphics drivers issues. So I checked my bios settings which were set to Nvidia Optimus mode disabled (the only way I could get the RC to install), and changed it to Optimus mode enable and the install all worked without an issue. However though as a laptop it work find,  including with a second external monitor. I did have to set Optimus back to disabled and run in discrete video mode if I wanted to use a projector. It seems the Optimus mode certainly gets confused with the Benq projector we have in the office, it will allow you to extend your desktop but not duplicate it. As soon as you switch back to discrete graphic mode all is OK (though you do lose the ability to run two external monitors)

On completing the installation I ran a Windows update which found an update Lenovo display driver (it had no effect on the Optimus issue) and Conexant audio driver (one I had to manually update on the RC to get Lync 2013 working).

However, on checking the Device Manager I was still missing drives for a couple of devices

image

I think they are Power Management and Intel AMT, but the beta drivers from Lenovo don’t seem to work so I will need to keep looking.

So now to see how it runs, first impressions are good, seem quick.

Moving podcast subscriptions with Zune
Thu, Aug 16 2012 10:29

If like me you listen to many podcasts, then swapping the PC your Phone7 syncs to collect the podcasta is a real pain. The problem being as far as I can see Zune has no podcast subscription export/import, so you are left with a lot of copy typing to re-enter them.

Whilst rebuilding my PC with Windows 8 today I have at least found a work around

  1. On your old Pc open you ‘c:\user\[user]\My Podcasts’ folder (shown in Windows Explorer as the ‘Podcast’ folder).
  2. You will see a folder for each podcast you are subscribed to
  3. Copy the whole folder to the same location on your new PC (I did via a USB drive as I was reformatting the disk on the same PC)
  4. Install Zune on the new PC
  5. Open Zune and look in the Collection>Podcasts, you should see all your podcast – but your are not subscribed yet
  6. In Zune, highlight and select all podcasts
  7. Right click and you should see  a Subscribe option, select it.
  8. Zune now sorts itself out re-subscribing and checking for new programmes
  9. It gets a bit confused over what you have watched so might pull them down again. Also you might want to alter subscription settings for specific podcasts as it will default back to just 3 programmes.
  10. When you are happy with your settings just drag the podcasts onto your newly resync’d mobile device to finish the job.
  11. You might need to look at the podcasts that are on the device as seems it does not removed one previously there via Zune (again it seems unsure of what you have listened too)

Not perfect but better than trying to removed load of site URLs

TF900546 error on a TFS 2012 build
Thu, Aug 9 2012 6:27

Whilst moving over to our new TFS 2012 installation I got the following error when a build tried to run tests

TF900546: An unexpected error occurred while running the RunTests activity: 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'.

This was a new one on me, and nothing of much use on the web other than a basic MSDN page.

Turns out the immediate fix is to just restart the build controller. Initially I did this after switching to the default build process template, and setting it to NOT load any custom activities, but I seems a simple restart would have been enough as once I re-enabled all custom activities it still worked.

As to the root cause I have no idea, one to keep an eye on, especially as I am currently on the RC, lets see what the RTM build does.

DDDNorth session voting is now open
Wed, Aug 8 2012 9:57

DDDNorth2 session voting is now open

Using an internal Nuget server to manage the Typemock assembly references.
Mon, Aug 6 2012 4:38

In my last post I discussed the process I needed to go through to get Typemock Isolator running under TFS 2012. In this process I used the Auto Deploy feature of Isolator. However this raised the  question of how to manage the references within projects. You cannot just assume the Typemock assemblies are in the GAC, they are not on the build box using auto deploy. You could get all projects to reference the auto deployment location in source control. However, if you use build process templates across projects it might be you do not want to have production code referencing build tools in the build process are directly.

For most issues of this nature we now use Nuget. At Black Marble we make use of the public Nuget repository for tools such as XUnit, SpecFlow etc. but we also have an internal Nuget repository for our own cross project code libraries. This includes licensing modules, utility and data loggers etc.

It struck me after writing the last post that the best way to manage my Typemock references was with a Nuget package, obviously not a public one, this would be for Typemock to produce. So I create one to place on our internal Nuget server that just contained the two DLLs I needed to reference (I could include more but we usually only need the core and act assert arrange assemblies).

image

IT IS IMPORANT TO NOTE that using a Nuget package here in no way alters the Typemock licensing. Your developers still each need a license, they also need to install Typemock Isolator, to be able to run the tests and your build box needs to use auto deployment. All using Nuget means is that you are now managing references in the same way for Typemock as any other Nuget managed set of assemblies. You are internally consistent, which I like.

So in theory as new versions of Typemock are released I can update my internal Nuget package allowing projects to use the version they require. It will be interesting to see how well this works in practice.

Getting Typemock Isolator running within a TFS 2012 build
Sat, Aug 4 2012 6:01

I have posted in the past about getting Typemock Isolator to function within the TFS build process. In TFS 2008 it was easy, you just ran a couple of MSBUILD tasks that started/stopped the Typemock Isolator inception process (the bit that does the magic other mocking frameworks cannot do). However with TFS 2010’s move to a windows workflow based build model it became more difficult. This was due to the parallel processing nature of the 2010 build process, running a single task to enable interception cannot be guaranteed to occur in the correct thread (or maybe even on the correct build agent). So I wrote wrapper build activity for MStest to get around this problem. Howerver, with the release of Typemock Isolator 6.2 direct support for TFS 2010 was added and these TFS build activities have been refined in later releases. In the current beta (7.0.8) you get a pre-created TFS build process template to get you going and some great auto deploy features, but more of that later.

The problem was I wanted to put Isolator based tests within a TFS 2012 build process. I posted before about my initial thoughts on the problem. The main problem is that TFS build activities have to be built against the correct version of the TFS API assemblies (this is the reason the community custom activities have two sets of DLLs in the release ZIP file). So out the box you can’t use the Typemock.TFS2010.DLL with TFS 2012 as it is built against the 2010 API.

Also you cannot just use the Typemock provided sample build process template. This is built against 2010 too, so full of 2010 activities which all fail.

What I tried that did not work (so don’t waste your time)

So I took a copy of the default TFS 2012 build process template and followed the process to add the Typemock.TFS2010.DLL containing the Typemock activities to the Visual Studio 2012 toolbox (the community activity documentation provides a good overview of this strangely complex process also see the ALM Rangers guidance). I then added the TypemockRegister and TypemockStart activities at the start of the testing block. For initial tests I did not both adding the TypemockStop activity

image

I then made sure that

  • Typemock was installed on the build agent PC
  • The Typemock.TFS2010.dll was in the correct CustomActivities folder in source control
  • The build controller was set to load activities from the CustomActivities folder.

However, when I tried to queue this build I got an error 

Exception Message: Object reference not set to an instance of an object. (type NullReferenceException)
Exception Stack Trace:    at TypeMock.CLI.Common.TypeMockRegisterInfo.Execute()

image 

The issue was that though Typemock was installed, the required DLLs could not be found. Checking in a bit more detailed (by running the build with diagnostic level of logging and using Fuslogvw) I saw it was trying load the wrong versions of DLLs as expected. So the first thing I tried to use was binding redirection (a technique I used before with similar Typemock). This in effect told the Typemock activity to use the 2012 DLLs when it asks for the 2010 ones. This is done by using an XML config file (Typemock.TFS2010.DLL.config)  in the same folder as the DLL file.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="Microsoft.TeamFoundation.Build.Workflow"
                           publicKeyToken="b03f5f7f11d50a3a"
                           culture="neutral" />
         <bindingRedirect oldVersion="10.0.0.0"
                          newVersion="11.0.0.0"/>
       </dependentAssembly>
       <dependentAssembly>
         <assemblyIdentity name="Microsoft.TeamFoundation.Build.Client"
                           publicKeyToken="b03f5f7f11d50a3a"
                           culture="neutral" />
         <bindingRedirect oldVersion="10.0.0.0"
                          newVersion="11.0.0.0"/>
       </dependentAssembly>
          <publisherPolicy apply="no">
      </assemblyBinding>bu
   </runtime>
</configuration>

I first tried to add this file to the CustomActivities source control folder, where the custom activities are loaded from by the build agent, but that did not work. I could only get it to work if I put both the DLL and the config files in the  C:\Program Files\Microsoft team Foundation Server 1.0\Tools folder on the build agent. This is not a way I like to work, too messy having to fiddle with the build agent file system.

Once this setting was made I tried a build again and got the build process to load, but the TypemockRegister activity failed as the Typemock settings argument was not set. Strangely Typemock have chosen to pass in their parameters as a complex type (of the type TypemockSettings) as opposed to four strings. Also you would expect this argument to be passed directly into their custom activities by getting activity properties to argument values, but this is not how it is done. The Typemock activities know to look directly for an argument called Typemock. This does make adding the activities easier, but not obvious if you are not expecting it. So I added this argument to the build definition in Visual Studio 2012 and checked it in, but when I tried to set the argument value for a specific build it gave the error that the DLL containing the type Typemock.TFS2010.TypemockSettings could not be loaded, again the TFS 2010/2012 API issue, this time within Visual  Studio 2012

 

clip_image002

 

At this point I gave up on binding redirection, I had wasted a lot more time than this post makes it sound. So I removed all the work I had previously done and thought again.

What did work

I decided that the only sensible option was to recreate the functionality of the Typemock activity against the 2012 API. So I used Telerik JustDecompile to open up the Typemock.Tfs2010.dll assembly and had a look inside. In Visual Studio 2012 I then created a new C# class library project called Typemock.BM.TFS20102 targeting .NET 4. I then basically cut and pasted the classes read from JustDecompile into classes of the same name in the new project. I then added references to the TFS 2012 API assemblies and any other assemblies needed and compiled the project. The one class I had problems with the TypemockStart, specifically the unpacking of the properties in the InternalExecute method. The reflected code by JustDecompile was full of what looked to be duplicated array copying which did not compile. So I simplified this to map the properties to the right names.

You can download a copy of my Typemock.BM.TFS2012.Dll from here, so you don’t have to go through the process yourself.

I now had a TFS 2012 custom build activity. I took this new activity and put it the CustomActivities folder. Next I took an unedited version of the default 2012 build process template and added these new Typemockregister, TypemockStart (at the start of the test block) and TypemockStop (at the end of the test block) activities as well as a Typemock argument (of TypemockSettings type). I checked this new template into TFS, and then created a build setting the Typemock argument settings.

 

image

Now at this point it is worth mentioning the nice feature of AutoDeploy. This allows you to use Typemock without having it installed on the build agent, thus making build agent management easier. You copy the AutoDeploy folder from the Typemock installation folder into source control (though a rename might be sensible so you remember it is for Typemock auto deployment and not anything else). You can then set the four argument properties

  • The location of the auto deployment folder in source control
  • A switch to enable auto deployment
  • Your Typemock license settings.

By using the auto deployment feature I was able to uninstall Typemock on the build agent.

So I tried a build using these setting, all the build activities loaded Ok and the TypemockSettings was read, but my project compile failed. As I had uninstalled Typemock on my build agent all the references to Typemock assemblies in the GAC failed. These references were fine on a development PC which had Typemock installed not on the build agent which did not.

So I needed to point the references in my project to another location. Typemock have thought of this too and provide a tools to remap the references that you can find on the Typemock menu

image

You can use this tool, or do it manually.

You could re-point the references to the same location you used for the AutoDeploy feature. However I prefer to keep my project references separate to my infrastructure (build activities etc.) as I use the same build templates cross project. For our projects we arrange source control so we have the structure in the general form (ignoring branch for simplicity)

/$
A team project
      BuildProcessTemplate
             CustomActivities
             AutoDeploy
      MyProject-1
             Src 
                   Solution1A.sln
             Lib 
                   [Nuget packages]
                   AutoDeploy
                   other assemblies
      MyProject-2
             Src 
                   Solution2a.sln
             Lib 
                   [Nuget packages]
                   AutoDeploy
                   other assemblies

I make sure we put all assemblies referenced in the lib folder, including those from Nuget using a nuget.config file in the src folder with the SLN file e.g.

<settings>
  <repositoryPath>..\Lib\</repositoryPath>
</settings>

This structure might not be to your taste, but I like it as it means all projects are independent, and so is the build process. The downside is you have to manage the references for the projects and build separately, but I see this as good practice. You probably don’t share want to reference and Nuget packages between separate projects/solutions.

So now we have a 2012 build process that can start Typemock Isolator, and a sample project that contains Typemock based tests, some using MSTest and some using XUnit (remember Visual Studio 2012 support multiple unit testing frameworks not just MSTest, see here on how to set this up for TFS build). When the build is run I can see all my unit tests pass to Typemock isolator must be starting correctly

 

image

So for me this is a reasonable work around until Typemock ship a TFS 2012 specific version. Hope this file saves you some time if you use Typemock and TFS 2012.