Release-only T4 transformation exception RRS feed

  • Question

  • I'm seeing what appears to be a spurious exception when transforming a T4 in Visual Studio (2010).  What's particularly interesting is that the transformation executes without any problems if I change the debug attribute value to true on the template directive, even if I don't actually attach a debugger.  The transformation also executes without errors under TextTransform.exe, regardless of the value of the template directive debug attribute.

    The above behaviour makes it just a wee bit tricky to try to find the actual problem.  I've seen similar behaviour at least once before (under VS 2008) and ended up distributing the template in debug mode since it was for internal use only.  I could do so again but, given that this now seems like a recurring problem, I'd like to try to track down the underlying issue if possible.

    In case it helps in any way, here's the transformation error:

    Could not instantiate a TextTransformation object from the compiled assembly. The following Exception was thrown:
    System.TypeLoadException: Method 'WriteAdderBody' in type 'Microsoft.VisualStudio.TextTemplatingD3B4144D12F41D100E402606626AECBF.GeneratedTextTransformation' from assembly 'weowelvn, Version=, Culture=neutral, PublicKeyToken=null' does not have an implementation.
      at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
      at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
      at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
      at Microsoft.VisualStudio.TextTemplating.TransformationRunner.CreateTextTransformation(String fullClassName, ITextTemplatingEngineHost host, Assembly assembly, ITextTemplatingSession userSession)

    "WriteAdderBody" is declared as an abstract method in the template base class, but the template code does implement the method.  The entire GeneratedTextTransformation class (WriteAdderBody implementation included) looks just fine in the .cs file saved under %userprofile%\Local Settings\Temp in debug mode, although that doesn't really provide any additional useful information given that transformation works just fine in debug mode.

    It would also seem that the compilation phase runs OK even in release mode since the exception seems to originate after the transformation assembly has already been generated.  However, given the above error, I do have some serious doubts about the results of that compilation.

    Any ideas regarding what might be causing the error would be much appreciated.  I'd also be interested to know if anyone has experienced a similar problem and whether it was ever resolved.  (My own earlier problems seemed to have resolved without any directed intervention since the problem template "spontaneously" reverted to working correctly in release mode during a later maintenance cycle.)

    Friday, November 12, 2010 2:40 PM

All replies

  • Hi Nicole - it sounds like something odd might be happening with the assembly caching.

    Can you try the follwowing to confrm that suspicion please? Usual caveats about backing up your registry first to avoid damage apply.

    Set a new registry value


    This will turn off assembly caching and put T4 into the model where it recycles its appdomain after a simple 25 turns.
    It also means that the assembly will


     never be cached between calls, but will be compiled fresh from the template text on every run.
    Gareth Jones - Developer Architect - T4, UML Designer Extensibility [MSFT]
    Friday, November 12, 2010 11:44 PM
  • Gareth,

    I had suspected potential caching problems early on in my investigations, so I asked a colleague to try it on his clean-ish machine.  Unfortunately, he saw the same error.

    I've tried setting the registry value as per your suggestion, but the error persisted.  (BTW, is that really supposed to be a string "false" as opposed to a dword 0?)


    Monday, November 15, 2010 5:39 PM
  • Yes, it is the string version.  It's a call to Boolean.ConvertTo on the value returned as object.

    Are you able to share your template with me?  garethj at microsoft dot com


    Gareth Jones - Developer Architect - T4, UML Designer Extensibility [MSFT]
    Monday, November 15, 2010 7:40 PM
  • Gareth,

    I've sent a sample by e-mail.  Please let me know if you do not receive it within a reasonable delay...


    Wednesday, November 17, 2010 4:47 PM
  • Gareth,

    Did you receive the sample?  If so, were you able to reproduce the problem?


    Tuesday, December 7, 2010 3:22 PM
  • Hi Nicole,

    Yes, I've repro'd the problem and I'm lookign at it now.

    Gareth Jones - Developer Architect - T4, UML Designer Extensibility [MSFT]
    Tuesday, January 18, 2011 10:00 PM
  • Thanks!
    Tuesday, January 25, 2011 6:44 PM
  • Did you ever get anywhere with this?  It's about to turn into a potentially more serious problem for us because our templates will be "escaping" our department to be used (usually after adaptation) by a wider developer pool that doesn't have the same depth of experience with template development.  While we can put comments in the original templates to always use debug mode, there's pretty much no way to avoid wasting time on supporting eventual "misuse" unless we can find and address the root cause of the problem.



    Thursday, September 1, 2011 12:58 PM