Does any one have source code for a working program that implements ITextTemplatingEngineHostI am trying to build a custom tool that does the same thing as the TextTemplatingFileGenerator custom tool that drives the T4 code generation process but is smart about how to find the XML files that I am using to drive my code generation process.  Right now, I am using hard-coded references to the files.  That works for the initial application but does not promote re-usability.  I specifically want to eliminate any hard-coded references to the files. <br><br>There seem to be several ways that I could achieve this goal.  First, I could put the logic to find the XML files into worker templates that I could include in each of the code generation templates; the templates are really just an appreviated programming language that are transformed into executable packages that generate the final code (very Zen like).  Second, I could split each template into a thicker worker template that did the work based upon parameters passed to it and was ignorant of the file locations and a thinner controlling template that invoked the worker template, passing the locations of the source XML files as parameters.   Third, I could embed the file location logic into a class that inherits from <a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.texttransformation.texttransformation.aspx">TextTransformation</a> class; I could define properties and methods in that class that the worker templates could invoke to get the model data.  Fourth, I could build a custom tool to replace the TextTemplatingFileGenerator custom tool that had all of the logic.<br><br>I went down the custom tool route because it seemed like this approach would be cleaner and would allow me to expand the logic into the MsBuild process or into a GUI-based tool.  I really like the way that the custom tool works in the stage of building the templates.  I have written the code (drawing from the example code in the MSDN article about ITextTemplatingEngineHost) but it throws the exception listed below.  I do not trust the source of the code completely because the code was clearly out of date with respect to the .NET 3.5 version of the interface.  The exception does not make any sense to me, but I think that I am safe in assuming that this is programmer error.  The only question is where is the error.  What I would like is the source code to a working implementration of a class that implements the ITextTemplatingEngineHost interface.<br><br>ErrorGeneratingOutput<br>C:\_Projects\Blog\CodeGeneration\CustomTemplateToolDriver\Test.tt(-1,-1) : error<br> : An Exception was thrown while running the transformation code. The process ca<br>nnot continue.  The following Exception was thrown:<br>System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudi<br>o.TextTemplating.Engine' in Assembly 'Microsoft.VisualStudio.TextTemplating, Ver<br>sion=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as<br> serializable.<br><br>Server stack trace:<br>   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMemb<br>ers(RuntimeType type)<br>   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type<br> type, StreamingContext context)<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberI<br>nfo()<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeriali<br>ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, S<br>erObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter<br>objectWriter)<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O<br>bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb<br>jectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter obje<br>ctWriter)<br>   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj<br>ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)<br>   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje<br>ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)<br>   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S<br>tream serializationStream, Object graph, Header[] headers, Boolean fCheck)<br>   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage<br>Parts(ArrayList argsToSerialize)<br>   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodC<br>allMessage mcm)<br>   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossi<br>ble(IMessage msg)<br>   at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMe<br>ssage reqMsg)<br><br>Exception rethrown at [0]:<br>   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req<br>Msg, IMessage retMsg)<br>   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgDa<br>ta, Int32 type)<br>   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformati<br>on(String fullClassName, String baseClassName, String[] importedNamespaces, Stri<br>ng[] references, String source, String inputFile, Boolean debug, SupportedLangua<br>ges language, IDictionary`2 languageOptions, IFormatProvider format, ITextTempla<br>tingEngineHost host, Boolean cacheAssemblies, String&amp; result)<br>   at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String gene<br>ratorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)<br><br>© 2009 Microsoft Corporation. All rights reserved.Mon, 03 Nov 2008 10:48:35 Z523f51f4-065c-47cd-85cc-328125974ae3http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#523f51f4-065c-47cd-85cc-328125974ae3http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#523f51f4-065c-47cd-85cc-328125974ae3Jon Stonecashhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jon%20StonecashDoes any one have source code for a working program that implements ITextTemplatingEngineHostI am trying to build a custom tool that does the same thing as the TextTemplatingFileGenerator custom tool that drives the T4 code generation process but is smart about how to find the XML files that I am using to drive my code generation process.  Right now, I am using hard-coded references to the files.  That works for the initial application but does not promote re-usability.  I specifically want to eliminate any hard-coded references to the files. <br><br>There seem to be several ways that I could achieve this goal.  First, I could put the logic to find the XML files into worker templates that I could include in each of the code generation templates; the templates are really just an appreviated programming language that are transformed into executable packages that generate the final code (very Zen like).  Second, I could split each template into a thicker worker template that did the work based upon parameters passed to it and was ignorant of the file locations and a thinner controlling template that invoked the worker template, passing the locations of the source XML files as parameters.   Third, I could embed the file location logic into a class that inherits from <a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.texttransformation.texttransformation.aspx">TextTransformation</a> class; I could define properties and methods in that class that the worker templates could invoke to get the model data.  Fourth, I could build a custom tool to replace the TextTemplatingFileGenerator custom tool that had all of the logic.<br><br>I went down the custom tool route because it seemed like this approach would be cleaner and would allow me to expand the logic into the MsBuild process or into a GUI-based tool.  I really like the way that the custom tool works in the stage of building the templates.  I have written the code (drawing from the example code in the MSDN article about ITextTemplatingEngineHost) but it throws the exception listed below.  I do not trust the source of the code completely because the code was clearly out of date with respect to the .NET 3.5 version of the interface.  The exception does not make any sense to me, but I think that I am safe in assuming that this is programmer error.  The only question is where is the error.  What I would like is the source code to a working implementration of a class that implements the ITextTemplatingEngineHost interface.<br><br>ErrorGeneratingOutput<br>C:\_Projects\Blog\CodeGeneration\CustomTemplateToolDriver\Test.tt(-1,-1) : error<br> : An Exception was thrown while running the transformation code. The process ca<br>nnot continue.  The following Exception was thrown:<br>System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudi<br>o.TextTemplating.Engine' in Assembly 'Microsoft.VisualStudio.TextTemplating, Ver<br>sion=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as<br> serializable.<br><br>Server stack trace:<br>   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMemb<br>ers(RuntimeType type)<br>   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type<br> type, StreamingContext context)<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberI<br>nfo()<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeriali<br>ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, S<br>erObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter<br>objectWriter)<br>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O<br>bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb<br>jectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter obje<br>ctWriter)<br>   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj<br>ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)<br>   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje<br>ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)<br>   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S<br>tream serializationStream, Object graph, Header[] headers, Boolean fCheck)<br>   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage<br>Parts(ArrayList argsToSerialize)<br>   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodC<br>allMessage mcm)<br>   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossi<br>ble(IMessage msg)<br>   at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMe<br>ssage reqMsg)<br><br>Exception rethrown at [0]:<br>   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req<br>Msg, IMessage retMsg)<br>   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgDa<br>ta, Int32 type)<br>   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformati<br>on(String fullClassName, String baseClassName, String[] importedNamespaces, Stri<br>ng[] references, String source, String inputFile, Boolean debug, SupportedLangua<br>ges language, IDictionary`2 languageOptions, IFormatProvider format, ITextTempla<br>tingEngineHost host, Boolean cacheAssemblies, String&amp; result)<br>   at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String gene<br>ratorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)<br><br>Wed, 29 Oct 2008 13:17:38 Z2008-10-29T13:17:38Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#a758e89d-8d02-4721-bec5-660f792c97ffhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#a758e89d-8d02-4721-bec5-660f792c97ffFengChenhttp://social.msdn.microsoft.com/Profile/en-US/?user=FengChenDoes any one have source code for a working program that implements ITextTemplatingEngineHost<dl class=authored><dt><span><a id="ctl00_rs1_mainContentContainer_ctl06" href="http://msdn.microsoft.com/en-us/library/bb126579.aspx">Walkthrough: Creating a Custom Text Template Host</a></span></dt></dl>Thanks.<br> <hr size="1" align="left" width="25%">Return to the source, learn the way!Thu, 30 Oct 2008 12:52:34 Z2008-10-30T12:52:34Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#fde755c9-78d0-4231-993a-0bff47bf90e1http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/523f51f4-065c-47cd-85cc-328125974ae3#fde755c9-78d0-4231-993a-0bff47bf90e1Jon Stonecashhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jon%20StonecashDoes any one have source code for a working program that implements ITextTemplatingEngineHost The ultimate answer to my issue may be found in the topic: <a href="http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/543a9fc6-0aa4-4cb9-86a1-cde6ade85867">http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/543a9fc6-0aa4-4cb9-86a1-cde6ade85867</a>.Mon, 03 Nov 2008 10:48:21 Z2008-11-03T10:48:21Z