This project is read-only.

TextTemplatingFileGenerator Specified Cast Is Not Valid

Feb 3, 2010 at 4:50 PM

FRUSTRATING and about ready to punt t4.  This is the second time TextTemplatingFileGenerator just stopped working in visual studio.  I am getting the warning

"The custom tool 'TextTemplatingFileGenerator' failed.  Specified cast is not valid. 

When I right click and hit run custom tool I get a modal message with the same above.

I then tried re-installing Visual Studio completely.  No Luck.

I am am Windows 7 64bit Visual Studio 2008.

Anyone else experienced this issue?  Can I use a different CustomTool.  What gives?  Very frustrating because it was working fine for months then all of the sudden just stopped.  No changes to the templates at all and it just stopped.





Feb 4, 2010 at 12:25 PM

I have seen this error reported on MSDN forums and StackOverflow. Unfortunately, I have never been able to duplicate it myself. Because you are one of a handful of people who can do it, the best way to solve it would be by contacting Microsoft support. Word from the DSL/T4 team is that having a call stack would be most helpful. Perhaps you could capture it by attaching a second instance of Visual Studio as a debugger, turning on the option to break in debugger when an exception is thrown and running the custom tool to trigger the error.


Feb 4, 2010 at 1:14 PM

Thanks Oleg

I have seen and used a bunch of your posts.  Thanks.  Unfortunately I was under the gun to get something completed.   As a result I reinstalled VS SDK, VS 2008 and SP1.  That seemed to fix the issue.  Next time I will definitely get a dump.  Nothewothy was this happened after I re-structured my solution file by moving the location of some commonly shared projects.  That is the only thing I can think of that was different.

In any case thanks for your reply.


My fingers are crossed that this does not happen again.