Can't Debug T4 Template using VS2012 feature

May 22, 2013 at 11:53 AM
Hi,
If I use the context menu item "Debug T4 Template" it always crashes as the debuging starts.
If I use the old method of Debugger.Launch() and Break() I can debug just fine.

Since the stack trace mentions T4Toolbox, I'm just wondering if this is a T4Toolbox issue?

Thanks

Server stack trace:
at T4Toolbox.VisualStudio.TransformationContextProvider.T4Toolbox.ITransformationContextProvider.GetMetadataValue(Object hierarchyObject, String fileName, String metadataName)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32
May 22, 2013 at 4:27 PM
Edited May 22, 2013 at 4:30 PM
Remove the T4Toolbox.tt line, and it debugs just fine
With it present, I get the exception as shown above
<#@ template  debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ include file="T4Toolbox.tt" #>
<#
    var t = new test();
#>
<#+
public class test
{
    public test()
    {
    }
}
#>
As afar as I can see the source for the VS2012 is not available here.
Pity...
Jun 18, 2013 at 2:26 AM
Edited Jun 18, 2013 at 2:29 AM
Having the same problem, with the same stack trace any time the T4Toolbox.tt include directive is in the file.
Errors were generated when initializing the transformation object. The transformation will not be run.  The following Exception was thrown:
System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace: 
   at T4Toolbox.VisualStudio.TransformationContextProvider.T4Toolbox.ITransformationContextProvider.GetMetadataValue(Object hierarchyObject, String fileName, String metadataName)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at T4Toolbox.ITransformationContextProvider.GetMetadataValue(Object hierarchy, String fileName, String metadataName)
   at T4Toolbox.TransformationContext.GetMetadataValue(String metadataName)
   at T4Toolbox.TransformationContext.InitializeParameters()
   at T4Toolbox.TransformationContext..ctor(TextTransformation transformation, StringBuilder generationEnvironment)
   at T4Toolbox.TransformationContext.Initialize(TextTransformation transformation, StringBuilder generationEnvironment)
   at Microsoft.VisualStudio.TextTemplating0B1CF1F3A969D870B9456C6DC780DB3FD94036B024C961C7C5F093D9024982F3DEE96E979A00EB665AB1C320A3F4402B7EB75EDE71AA9E8A56A296A0A19FAD9B.GeneratedTextTransformation.Initialize() in c:\confidential\path\hidden\myt4toolkitscript.tt:line 16
   at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0)
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation()
Originally I thought it was perhaps due to some sort of complexity generating multiple files with a template, etc, as described here, but even with a simple script, if T4Toolbox.tt is included, cannot debug using the 2012 context menu feature.

I can successfully debug using Debugger.Launch(), but Debugger.Break() causes visual studio to crash. I'm glad I can at least debug, but right-clicking on a menu item is obviously much faster than manually attaching the debugger.
Jun 18, 2013 at 8:37 AM
Hi,
Yes, Oleg has confirmed with me by private email that he has seen this bug.
It would appear that the bug was due to be fixed in Update 2 of VS2012 but clearly not, to Oleg's surprise.
He's finding out whether it is in Update 3, or whether we need to wait for VS2013.
I see that Update 3 RC is out. I might try this later in the week.
Meanwhile. I do have a VS2012 version of the code here on Codeplex you could have if you need to continue with your T4 development.
Cheers
John