# Encapsulating TX Text Control in Class Libraries

> This article describes how to encapsulate TX Text Control in class libraries. This is useful if you want to use TX Text Control in multiple projects and you want to avoid code duplication.

- **Author:** Bjoern Meyer
- **Published:** 2024-01-09
- **Modified:** 2026-07-17
- **Description:** This article describes how to encapsulate TX Text Control in class libraries. This is useful if you want to use TX Text Control in multiple projects and you want to avoid code duplication.
- **5 min read** (858 words)
- **Tags:**
  - ASP.NET
  - Windows Forms
  - WPF
  - Licensing
  - User Control
  - Class Library
- **Web URL:** https://www.textcontrol.com/blog/2024/01/09/encapsulating-tx-text-control-in-class-libraries/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/01/09/encapsulating-tx-text-control-in-class-libraries/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/01/09/encapsulating-tx-text-control-in-class-libraries/llms-full.txt

---

> **Important**
> 
> This article applies to TX Text Control 32.0 SP2 and later. This functionality is not available in older versions of TX Text Control.

Wrapping third-party components is a common standard for reusing functionality in different places in a project or across projects. By encapsulating the library into a separate class, you can write unit tests for the specific functionality you need. Changes to the library can be made with confidence, knowing that the remaining codebase will be affected as little as possible.

Since TX Text Control 32.0 SP2, wrappers can include the required license and these class libraries can be used in unlicensed projects.

This article describes how to encapsulate TX Text Control in class libraries. This is useful if you want to use TX Text Control in multiple projects and you want to avoid code duplication.

### Creating a Class Library

In the first step, we are going to create a new project for the class library in Visual Studio.

1. Open Visual Studio and create a new project. Select *Class Library* as the project template.
    
    ![Class library](https://s1-www.textcontrol.com/assets/dist/blog/2024/01/09/a/assets/visualstudio1.webp "Class library")
2. Enter a name for the project and click *Next*.
3. On the next page, select *.NET 8 (Long Term Support)* as the *Framework* and click *Create*.

### Adding the NuGet Packages

After creating the project, we need to add the TX Text Control NuGet packages to the project.

4. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu..
5. Select *Text Control Offline Packages* from the *Package source* drop-down.
    
    Install the latest versions of the following package:
    
    
    - *TXTextControl.TextControl.ASP.SDK*
    
    ![TXTextControl Package](https://s1-www.textcontrol.com/assets/dist/blog/2024/01/09/a/assets/visualstudio2.webp "TXTextControl Package")
    
    > **Use any Text Control Component**
    > 
    > This tutorial uses the ServerTextControl package that is available for TX Text Control .NET Server. However, the concept is not limited to this component, but can be applied to any component that uses any platform, including Windows Forms, ASP.NET, and WPF.
6. Click on the *Install* button to add the packages to the project.

### Specifying the Entry Assembly

As of 32.0 SP2, TX Text Control can be used in class libraries and called from other unlicensed assemblies. In previous versions of TX Text Control, the license must have been compiled into the main calling assembly. The new static property *EntryAssembly* has been introduced to allow you to specify where TX Text Control should look for the license.

7. Open *Class1.cs* and add the following constructor code to make the whole file look like this::
    
    ```
    namespace MyWrapper
    { 	
      public class Class1
      {
        public Class1()
        {
          TXTextControl.ServerTextControl.EntryAssembly = typeof(Class1).Assembly;
        }
      }
    }
    ```

The assembly setting defines where TX Text Control looks for the license. In the above example, the class library itself contains the license, and TX Text Control will look for the license in the class library.

This allows another assembly to call members that use TX Text Control without a reference or license to TX Text Control.

### Adding a Method

Now, we are going to add a method that uses the ServerTextControl class to return an HTML string.

8. Open *Class1.cs* and add the following method code to make the whole file look like this::
    
    ```
    namespace MyWrapper
    { 	
    	public class Class1
        {
            public Class1()
            {
                TXTextControl.ServerTextControl.EntryAssembly = typeof(Class1).Assembly;
            }
    
            public string GetHtml()
            {
                using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
                {
                    tx.Create();
                    tx.Text = "Hello World!";
    
                    var html = "";
                    tx.Save(out html, TXTextControl.StringStreamType.HTMLFormat);
                    return html;
                }
            }
        }
    }
    ```

### Creating the Consuming Project

Now, we are going to create a new project that consumes the class library. This project can be a Windows Forms, WPF, or ASP.NET project. In this tutorial, we will use a .NET Console App.

8. Select your *Solution* in the *Solution Explorer* and click *File -> Add -> New Project...*.
9. Select *Console App* as the project template and confirm with *Next*.
10. Enter a name for the project and click *Next*.
11. On the next page, select *.NET 8 (Long Term Support)* as the *Framework* and click *Create*.

### Adding Project References

After creating the project, we need to add a reference to the class library project.

12. In the *Solution Explorer*, select your created project and choose *Add -> Project Reference...* from the *Project* main menu.
13. Click on the *Projects* tab and select the class library project.
    
    ![Add Reference](https://s1-www.textcontrol.com/assets/dist/blog/2024/01/09/a/assets/visualstudio3.webp "Add Reference")
14. Click on the *OK* button to add the reference to the project.

### Calling the Wrapper

Now, we can call the wrapper class from the consuming project. In this example, we are going to create a new instance of the wrapper class and call the *Load* method to load a document from a file.

15. Open *Program.cs* and add the following code to make the whole file look like this::
    
    ```
    using MyWrapper;
    
    Class1 class1 = new Class1();
    Console.WriteLine(class1.GetHtml());
    ```

### Conclusion

TX Text Control can be easily encapsulated into class libraries. This allows you to reuse the functionality in multiple projects and to write unit tests for the specific functionality you need. TX Text Control does not require a direct reference or license from the calling project.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [TX Text Control 32.0 SP2 Licensing Changes: Say Goodbye to licenses.licx](https://www.textcontrol.com/blog/2024/01/05/tx-text-control-32-0-sp2-licensing-changes/llms.txt)
- [TX Text Control 34.0 SP4 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/05/20/tx-text-control-34-0-sp4-is-now-available/llms.txt)
- [TXTextControl.Markdown.Core 34.1.0-beta: Work with Full Documents, Selection, and SubTextParts](https://www.textcontrol.com/blog/2026/04/14/txtextcontrol-markdown-core-34-1-0-beta-work-with-full-documents-selection-and-subtextparts/llms.txt)
- [TX Spell .NET 11.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/04/08/tx-spell-net-11-0-sp1-is-now-available/llms.txt)
- [TX Text Control 34.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/02/18/tx-text-control-34-0-sp2-is-now-available/llms.txt)
- [TX Text Control 34.0 SP1 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/12/03/tx-text-control-34-0-sp1-is-now-available/llms.txt)
- [Introducing TX Text Control 34.0: Your Next Leap in Document Processing](https://www.textcontrol.com/blog/2025/11/10/introducing-tx-text-control-34-0-your-next-leap-in-document-processing/llms.txt)
- [Sneak Peek: TX Text Control 34.0 Coming November 2025](https://www.textcontrol.com/blog/2025/10/02/sneak-peek-tx-text-control-34-0-coming-november-2025/llms.txt)
- [TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/08/14/tx-text-control-33-0-sp3-is-now-available/llms.txt)
- [TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2025/06/18/tx-text-control-33-0-sp2-is-now-available/llms.txt)
- [Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format](https://www.textcontrol.com/blog/2025/05/16/document-lifecycle-optimization-leveraging-tx-text-controls-internal-format/llms.txt)
- [Expert Implementation Services for Legacy System Modernization](https://www.textcontrol.com/blog/2025/05/07/expert-implementation-services-for-legacy-system-modernization/llms.txt)
- [Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5](https://www.textcontrol.com/blog/2025/05/07/service-pack-releases-whats-new-in-tx-text-control-33-0-sp1-and-32-0-sp5/llms.txt)
- [Top 5 Real-World Applications for TX Text Control Document Processing Libraries](https://www.textcontrol.com/blog/2025/04/01/top-5-real-world-applications-for-tx-text-control-document-processing-libraries/llms.txt)
- [DWX Developer Week Moves to Mannheim - And Text Control Is on Board!](https://www.textcontrol.com/blog/2025/03/19/dwx-developer-week-moves-to-mannheim-and-tx-text-control-is-on-board/llms.txt)
- [The Wait is Over: TX Text Control for Linux is Officially Here](https://www.textcontrol.com/blog/2025/03/12/the-wait-is-over-tx-text-control-for-linux-is-officially-here/llms.txt)
- [Full .NET 9 Support in Text Control .NET Components for ASP.NET Core, Windows Forms, and WPF](https://www.textcontrol.com/blog/2024/11/11/full-net-9-support-in-text-control-net-components-for-asp-net-core-windows-forms-and-wpf/llms.txt)
- [Toggle Field Codes in TX Text Control](https://www.textcontrol.com/blog/2024/11/07/toggle-field-codes-in-tx-text-control/llms.txt)
- [TX Text Control 32.0 Service Pack 4 Released](https://www.textcontrol.com/blog/2024/09/02/tx-text-control-32-0-service-pack-4-released/llms.txt)
- [Service Pack 3: MailMerge Supports SVG Images](https://www.textcontrol.com/blog/2024/04/29/service-pack-3-mailmerge-supports-svg-images/llms.txt)
- [TX Text Control 32.0 Service Pack 3 Released](https://www.textcontrol.com/blog/2024/04/29/tx-text-control-32-0-service-pack-3-released/llms.txt)
- [Electronic Invoicing will Become Mandatory in Germany in 2025](https://www.textcontrol.com/blog/2024/04/10/electronic-invoicing-will-become-mandatory-in-germany-in-2025/llms.txt)
- [Inserting MergeBlocks with the DataSourceManager and Applying Table Styles in C#](https://www.textcontrol.com/blog/2024/04/09/inserting-mergeblocks-with-the-datasourcemanager-and-applying-table-styles-in-csharp/llms.txt)
- [The Power of SubTextParts: Typical Use Cases](https://www.textcontrol.com/blog/2024/02/09/the-power-of-subtextparts-typical-use-cases/llms.txt)
- [Renaming Merge Blocks and Merge Fields Programmatically in C#](https://www.textcontrol.com/blog/2024/02/08/renaming-merge-blocks-and-merge-fields-programmatically-in-csharp/llms.txt)
