Wednesday, June 30, 2010

T4 error: Compiling transformation: Invalid token 'this' in class, struct, or interface member

If you have a T4 Template .tt file that throws a weird Compiling transformation: Invalid token 'this' in class, struct, or interface member error that seems to come out of nowhere, try to delete extraneous spaces.

In my case, I has copied/pasted the .tt content from a web page and I was trying to understand why it wouldn't work. I right clicked on the source, went to Advanced, chose Convert all spaces to tabs, then back to Convert all tabs to spaces. Then it worked. I guess some white spaces where not really spaces or some other formatting issue.

If you don't have the options when you right click, it might be that they are features of the Tangible T4 Editor.

4 comments:

Mohamed Rashed said...

Thank you very much, your post help me a lot

Anonymous said...

Thanks so much for this post. Once I knew what to look for I found a line with a log of whitespaces. Removed them and all is working.

Anonymous said...

Hi, I am using Visual Studio 2013, I have downloaded Tangible T4 Editor but I do not get an option to go to Advanced, chose Convert all spaces to tabs.

Can you please help?

Many Thanks!

Siderite said...

Sorry, I haven't done this in years. Try to find the solution yourself and, perhaps, leave a comment on how you did it...