This project has moved. For the latest updates, please go here.
1
Vote

CSD files not generated and "TextTemplating service unavailable" error is shown.

description

I don't know how many people have had this problem (it was years before I first saw it), but it's worth investigating and fixing.

Someone reported this in the VS2010 downloads page, and I FINALLY was able to reproduce (Except I was using VS2013). What happened to me, is I performed actions in a certain order that caused that project file to stop working with ANY CSDs (new or old).

UPDATE: This sentence is false after further testing! The order of actions I performed (see bottom of this post) caused the text "<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />" to be added to the csproj file. If this text is deleted, the CSDs work again.

Next steps would be to:
  • Find out why this service reference gets added to the csproj file when the specific steps are performed.
  • See if we can properly handle the situation where this reference is present, and allow the CSD to work. NOTE: I would say try to PREVENT this ref from being added (which is still a good idea), but we probably need to handle this correctly for users who NEED this service reference.
With my current research data included below, we should be able to figure this one it without too much difficulty.

LATEST ANALYSIS
It looks like the problem occurs because PROJECT file in MEMORY has some object in an invalid state until it is reloaded from FILE. The project file being more up-to-date than MEMORY does not appear to be an issue since problem occurs even BEFORE project file is updated. Something in the project in MEMORY is invalid, but what is it?

**** EXCEPTION DETAILS ****

------ CSD file generation started: Configuration document: C:\Users\amoore\Documents\Visual Studio 2013\Projects\GKConfigDemo\UseCaseDemos.Configuration\IntraElementDependencies.csd ------
  • Searching for configuration project handle... found!
    [ ERROR ENCOUNTERED! ] TextTemplating service unavailable
    at Microsoft.VisualStudio.TextTemplating.VSHost.BaseTemplatedCodeGenerator.GenerateCode(String inputFileName, String inputFileContent)
    at Microsoft.VisualStudio.TextTemplating.VSHost.TemplatedCodeGenerator.GenerateCode(String inputFileName, String inputFileContent)
    at ConfigurationSectionDesigner.CsdFileGenerator.TemplateCodeGenerator.GenerateCode(String inputFileName, String inputFileContent)
    at ConfigurationSectionDesigner.CsdFileGenerator.GenerateAllContent(String fileExtension)
    at ConfigurationSectionDesigner.CsdFileGenerator.GenerateContent(String element)
    at ConfigurationSectionDesigner.VsMultipleFileGenerator`1.Generate(String wszInputFilePath, String bstrInputFileContents, String wszDefaultNamespace, IntPtr[] rgbOutputFileContents, UInt32& pcbOutput, IVsGeneratorProgress pGenerateProgress)

**** My response to user in VS2010 DL page

UPDATE: Removed since this response is false after further testing!

**** Steps I performed to reliably trigger this error.

WHAT I DID IN BAD PROJ

Create new class library proj. in EXISTING or NEW solution.
  • Add new CSD item (ConfigurationSectionDesigner1).
    • csproj file NOT modified here.
  • Save ConfigurationSectionDesigner1.
    • csproj file NOT modified here.
  • Add new CSD item (ConfigurationSectionDesigner2).
    • csproj file NOT modified here.
  • SAVE ConfigurationSectionDesigner2.
    • NO ERROR!
  • Save ConfigurationSectionDesigner2.
    • csproj file NOT modified here.
  • DELETE ConfigurationSectionDesigner1. [ This where problem is created!!! ]
  • Open ConfigurationSectionDesigner2 diagram.
  • Save ConfigurationSectionDesigner2 diagram.
    • ERROR OCCURS!!!!!! But csproj file still not saved to disk.
  • RELOAD project (Unload project, then reload).
    • Problem goes away!
Another Set Of Steps to Reproduce

Create new class library proj. in EXISTING or NEW solution.
  • Add new CSD item (ConfigurationSectionDesigner1).
    • csproj file NOT modified here.
  • Add new CSD item (ConfigurationSectionDesigner2).
    • csproj file NOT modified here.
  • SAVE ConfigurationSectionDesigner2.
    • NO ERROR!
  • DELETE ConfigurationSectionDesigner1. [ This where problem is created!!! ]
    • csproj file NOT modified here.
  • Open ConfigurationSectionDesigner2 diagram.
  • Save ConfigurationSectionDesigner2 diagram.
    • ERROR OCCURS!!!!!! But csproj file still not saved to disk.
    • NOTE: This is weird... Project in memory would seem to be more up to date at this point than the file.
  • At this point, adding, deleting new CSD files does not fix issue. All CSDs in project fail to build.
  • REBUILD Solution
    • csproj file IS modified here!!!
  • Save ConfigurationSectionDesigner2 diagram.
    • ERROR OCCURS!!!!!!
  • RELOAD project (Unload project, then reload).
    • Problem goes away!!!

comments

andym1978 wrote Nov 12, 2014 at 3:55 PM

MORE INFO for DEBUGGING::::

In source code, the error occurs when calling TemplateGenerator.GenerateCode in the FileGeneration.cs file. Content below should help developer locate area in FileGeneration.cs file:

System.Diagnostics.Debugger.Log(0, "", String.Format("Replacing $inputFileName$ with real value before running TemplateGenerator.GenerateCode(InputFilePath={0},inputFileContent.Length={1}); ", InputFilePath, inputFileContent.Length));
inputFileContent = inputFileContent.Replace("$inputFileName$", InputFilePath);
return TemplateGenerator.GenerateCode(InputFilePath, inputFileContent); // FAILS HERE.

Failure occurs in BaseTemplatedCodeGenerator (Microsoft class) during a check to see if TextTemplating property is NULL. Source code of this property accessor are below:


protected ITextTemplating TextTemplating
{
get
{
ITextTemplating textTemplating = (ITextTemplating) null;
IVsHierarchy vsHierarchy = this.GetService(typeof (IVsHierarchy)) as IVsHierarchy;
if (vsHierarchy != null)
{
    Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider) null;
    if (!Microsoft.VisualStudio.TextTemplating.NativeMethods.Failed(vsHierarchy.GetSite(out ppSP)) && ppSP != null)
    {
    Guid guid = typeof (STextTemplating).GUID;
    IntPtr ppvObject = IntPtr.Zero;
    ErrorHandler.ThrowOnFailure(ppSP.QueryService(ref guid, ref guid, out ppvObject));
    if (ppvObject != IntPtr.Zero)
        textTemplating = Marshal.GetObjectForIUnknown(ppvObject) as ITextTemplating;
    }
}
return textTemplating;
}
}

andym1978 wrote Nov 26, 2014 at 2:40 PM

UPDATE:
I did another test and discovered that the service reference mentioned previously is NOT the problem. Just unloading, then reloading the project fixes the issue. No changes to project file are required. It seems like something is not updating in memory for the project. Back to the drawing board...

wrote Nov 26, 2014 at 3:13 PM