How to Fix the T4 Debugger in Visual Studio 16.9.X

Visual Studio 16.9 introduced a bug that prevents us from debugging T4 templates. The debugger rushes to the end of the template and fails with this message:

FileLoadException: Could not load file or assembly ‘Microsoft.VisualStudio.Validation, Version=16.8.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The problem is the reference to version 16.8 of Microsoft.VisualStudio.Validation that no longer exists in Visual Studio 16.9. We can fix this problem with a binding redirect:

  1. open the directory C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE
  2. edit the file T4VSHostProcess.exe.config in Admin mode
  3. add the binding redirect as the first entry in the <probing>-tag (line 7):

  4. save the file
  5. restart Visual Studio

Visual Studio should now debug your T4 templates as it did in 16.8 and older:

The debugger now works and stops at your breakpoints

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.