Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7945659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:56:08+00:00 2026-06-04T00:56:08+00:00

When I try to access the Host object from a non-static method declared in

  • 0

When I try to access the Host object from a non-static method declared in <#+#> brackets, everything works ok. But I need to access it from a class method, like this:

<#+
public class ProjectTraverser
{
    public void Traverse()
    {
        var a = Host;
    }
}
#>

I get the following error when this template executes: “Compiling transformation: Cannot access a non-static member of outer type ‘Microsoft.VisualStudio.TextTemplating7D03DF372FEAC3D3A28C011A41F02403.GeneratedTextTransformation’ via nested type ‘Microsoft.VisualStudio.TextTemplating7D03DF372FEAC3D3A28C011A41F02403.GeneratedTextTransformation.ProjectTraverser’ d:\Projects\Test Solutions\GettingStarted\TelerikMvc3RazorApplication\TextTemplate2.tt”

Please share any ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:56:10+00:00Added an answer on June 4, 2026 at 12:56 am

    As FuleSnabel commented, the declaration you’re making is for a nested type, which doesn’t have access to the instance variable in the enclosing type that represents the template.

    What you’ll want to do is add a Host property of type ITextTemplatingEngineHost to the ProjectTraverser class (probably static) and then set it from the main template.

    In retrospect, I wish I’d made the main Host property static, as it’s not really sensible to imagine multiple hosts for different instances of the same template in the same AppDomain, but you live and learn.

    Here’s a rough example:

    <#@ template hostspecific="true' #>
    <#
        ProjectTraverser.Host = Host;
    #>
    <#+ 
    public class ProjectTraverser 
    {
        public static ITextTemplatingEngineHost Host { get; set; }
    
        public void Traverse() 
        { 
            var a = Host; 
        } 
    } 
    #> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to access the MainContentBlock control from the aspx, but unable to do
Whenever I try to create a mysqli object, as in; $mysqli = new mysqli(host,
I'm using pycurl to access a JSON web API, but when I try to
When you try to access a key which isn't in a Dictionary (for example),
When I try to access info that is not presented in xml like so:
My app crash when I try to access any property of my NSDecimalNumber amount_before_current_year:
The error message I gen when I try to access the web page server
I am having an issue where I try to access the Lists.asmx web service
I have a scenario that when I try to access a hash key using
I get this wired error only when I try to access the web page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.