Building TX Text Control AnyCPU Applications
In Visual Studio, the configuration manager can be used to specify the platform the code should be compiled for. Possible platforms are x86, x64 and AnyCPU. Due to fact that TX Text Control provides two different sets of assemblies specifically designed for 32bit and 64bit, AnyCPU can't be used out-of-the-box. At the recent conference BASTA!, I discussed this topic with one of our users at our booth. Thanks Ramon Kania for the input! He suggested a solution that allows you to compile and…

In Visual Studio, the configuration manager can be used to specify the platform the code should be compiled for. Possible platforms are x86, x64 and AnyCPU. Due to fact that TX Text Control provides two different sets of assemblies specifically designed for 32bit and 64bit, AnyCPU can't be used out-of-the-box.
At the recent conference BASTA!, I discussed this topic with one of our users at our booth. Thanks Ramon Kania for the input! He suggested a solution that allows you to compile and deploy applications built as AnyCPU.
The core idea is to change the path of the assemblies dynamically. The AppDomain.AssemblyResolve event can be used to load the assemblies from another path. Thus enables you to compile your application as AnyCPU. You only need to distribute both sets of DLLs and depending on the current platform, the proper assemblies are loaded.
public static void HookOnCurrentAppDomain()
{
HookOnAppDomain(AppDomain.CurrentDomain);
}
public static void HookOnAppDomain(AppDomain appDomainToHookOn)
{
appDomainToHookOn.AssemblyResolve += AppDomain_AssemblyResolve;
}
private static Assembly AppDomain_AssemblyResolve(object sender,
ResolveEventArgs args)
{
return (args.Name.StartsWith("TXTextControl") ||
args.Name.StartsWith("TXDocumentServer")) &&
!args.Name.Contains(".resources")
? LoadAssembly(args)
: null;
}
private static Assembly LoadAssembly(ResolveEventArgs args)
{
return Assembly.LoadFrom(Path.Combine(
IntPtr.Size == 8 ? FolderNameX64 : FolderNameX86,
string.Concat(args.Name.Split(\',\')[0], ".dll")));
}
}
IntPtr.Size is a very clean way of detecting the platform. The value of this property is 4 on a 32-bit platform, and 8 on a 64-bit platform.
In the following sample application, the TX Text Control distributables must simply be copied into two different folders: x86 for the 32-bit files and x64 for the 64-bit files.
You can download a very basic example of this elegant solution here:
tx_anycpu_deployment.zipRelated Posts
Windows FormsGetting StartedTutorial
Windows Forms Tutorial: Create Your First Windows Forms C# Application
This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.
How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#
Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…
Creating an Angular Document Editor Application with a Node.js WebSocket Server
This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.
Adding SVG Watermarks to Documents
This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.
Using MailMerge in ASP.NET Core 6 Web Applications
This article shows how to use the TX Text Control ASP.NET MailMerge class to merge templates with JSON data within a .NET 6 application in Visual Studio 2022.