Cообщество разработчиков на платформе Microsoft > Форумы > Visual Studio Extensibility > How to handle Serialization Issue with a Custom Host Implementing ITextTemplatingEngineHost
Задайте вопросЗадайте вопрос
 

ОтвеченоHow to handle Serialization Issue with a Custom Host Implementing ITextTemplatingEngineHost

  • 1 ноября 2008 г. 22:02Jon Stonecash Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    As I noted in an earlier post :Source Code for a Working Implementation of ITextTemplatingEngineHost, I am trying to build a custom host for T4.  The answer to my query about available source code for a working custom host lead to the code in the MSDN documentation.  That code worked.  Using that code as a baseline, I was able to isolate the cause of my problem. 

    My situation is that I want to expose the custom host in the template file.  Following the example in MSDN, I wrote the following code for the ProvideTemplatingAppDomain:

            public AppDomain ProvideTemplatingAppDomain(string content)
            {
                // This host will provide a new application domain each time the
                // engine processes a text template.
                // -------------------------------------------------------------
                return AppDomain.CreateDomain("Generation App Domain");
            }

    This works fine if I supply a new AppDomain but do not include the "hostspecific=true" parameter on the template directive.  It also works just fine if I supply the current Appdomain and include the "hostspecific=true" parameter.  It DOES NOT WORK if I supply a new AppDomain and also include the "hostspecific=true" parameter.  The issue is that the Engine class is not serializable.  Apparently, it must be serializable to move across the AppDomain boundary.

    I have to specify the "hostspecific=true" parameter to make the functionality that I am trying to provide work.  In the short term, I can work around this by re-using the AppDomain, but I wonder how that will affect Visual Studio performance.  Am I right in thinking that the custom tool will run in a separate process space?  If it does, the AppDomains will only live for the duration of the code generation process; there would be no accumulation in memory.  But the author of the MSDN sample took some effort to mention that creating a searpate AppDomain was a good idea.  Is there a way to get a new AppDomain and "host specific" at the same time?

    Jon Stonecash

Ответы

Все ответы