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:
- open the directory C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE
- edit the file T4VSHostProcess.exe.config in Admin mode
- add the binding redirect as the first entry in the <probing>-tag (line 7):
1234<dependentAssembly><assemblyIdentity name="Microsoft.VisualStudio.Validation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/><bindingRedirect oldVersion="12.0.0.0-16.9.0.0" newVersion="16.9.0.0"/></dependentAssembly>< - save the file
- restart Visual Studio
Visual Studio should now debug your T4 templates as it did in 16.8 and older: