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 9216229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:22:19+00:00 2026-06-18T02:22:19+00:00

I am using VS 2010 (C#) T4 templates to generate code. I need to

  • 0

I am using VS 2010 (C#) T4 templates to generate code.

I need to iterate through all types within my project, shortlist entity poco classes and generate wrappers. The problem is, the project namespace is not being recognized.

Here is the solution structure:

namespace MySolution.Entities
{
    public class Employee { ... }
    public class Department { ... }
}

// Seperate project referenceing MySolution.Entities.
namespace MySolution.Database
{
    public partial class Context { ... }

    // Should generate Context.cs as a partial class with after iterating Syste.Types available in MySolution.Entities.
    Context.tt
}

Here is the text template:

<#@ template language="C#" #>
<#@ Output Extension=".cs" #>

namespace MySolution.Database
{
    public partial class Context:
        System.Data.Entity.DbContext
    {
<#
System.Type [] types = typeof(MySolution.Entities).Assembly.GetTypes();
for (int i=0; i < types.Count; i++)
#>
        public <#= types[i].Name; #> <#= types[i].Name; #> { get; set; }
    }
}

The above code generates an error: The type or namespace ‘MySolution’ cannot be found. Are you missing a using directive or an assembly reference? I then put the following line of code to include the assembly:

<#@ Assembly Name="..\MySolution.Entities\bin\x86\Release\MySolution.Entities.dll" #>

Now it gives me a different error: The host threw an exception while trying to resolve the assembly reference ‘..\..\..TrafficMonitor.Core\bin\x86\Release\TrafficMonitor.Library.dll’. The transformation will not be run. The following Exception was thrown:
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

Any ideas on how to overcome this limitation?

  • 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-18T02:22:21+00:00Added an answer on June 18, 2026 at 2:22 am

    The error is because the T4 template processor is unable to find your assembly.

    It should find the assembly if you use the full path to the assembly in the Assembly directive in your T4 template. A better approach to using the full path is to use the one of the Visual Studio macro variables, such as $(SolutionDir), which will be expanded when your T4 template is executed.

    <#@ Assembly Name="$(SolutionDir)MySolution.Entities\bin\x86\Release\MySolution.Entities.dll" #>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I generate code using T4 templates in Visual Studio 2010, I get the
I've started using poco templates so that I can generate the pocos for my
I created a new project using aspx visual studio 2010. All I am trying
I have been using Entity Framework model first since VS 2010. When I build
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a
Ok, I'm using Visual Studio 2010 to mess with lambdas in templates. VC++ has
Is there any way to generate a ToString() using Visual Studio 2010? I really
I used the ADO.NET C# POCO Entity Generator Visual Studio add-in to generate POCO
Is this really the expected behavior? I'm using the standard T4 POCO templates (but
i'm trying to generate html pages by using xslt (using VS 2010 as the

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.