MSDN > Home page del forum > Visual Studio Extensibility > How to handle Serialization Issue with a Custom Host Implementing ITextTemplatingEngineHost
Formula una domandaFormula una domanda
 

Con rispostaHow to handle Serialization Issue with a Custom Host Implementing ITextTemplatingEngineHost

  • sabato 1 novembre 2008 22.02Jon Stonecash Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     

    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

Risposte

  • domenica 2 novembre 2008 13.36Oleg V. SychMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Jon,

    I think that changing your host class to inherit from MarshalByRefObject should resolve the serialization issue and allow you to access the host from a "hostspecific" template running in a new AppDomain.



    Oleg
    • Contrassegnato come rispostaJon Stonecash lunedì 3 novembre 2008 10.46
    •  

Tutte le risposte