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

  • SEARCH
  • Home
  • 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 58603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:52:26+00:00 2026-05-10T17:52:26+00:00

We have two versions of a managed C++ assembly, one for x86 and one

  • 0

We have two versions of a managed C++ assembly, one for x86 and one for x64. This assembly is called by a .net application complied for AnyCPU. We are deploying our code via a file copy install, and would like to continue to do so.

Is it possible to use a Side-by-Side assembly manifest to loading a x86 or x64 assembly respectively when an application is dynamically selecting it’s processor architecture? Or is there another way to get this done in a file copy deployment (e.g. not using the GAC)?

  • 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. 2026-05-10T17:52:26+00:00Added an answer on May 10, 2026 at 5:52 pm

    I created a simple solution that is able to load platform-specific assembly from an executable compiled as AnyCPU. The technique used can be summarized as follows:

    1. Make sure default .NET assembly loading mechanism (‘Fusion’ engine) can’t find either x86 or x64 version of the platform-specific assembly
    2. Before the main application attempts loading the platform-specific assembly, install a custom assembly resolver in the current AppDomain
    3. Now when the main application needs the platform-specific assembly, Fusion engine will give up (because of step 1) and call our custom resolver (because of step 2); in the custom resolver we determine current platform and use directory-based lookup to load appropriate DLL.

    To demonstrate this technique, I am attaching a short, command-line based tutorial. I tested the resulting binaries on Windows XP x86 and then Vista SP1 x64 (by copying the binaries over, just like your deployment).

    Note 1: ‘csc.exe’ is a C-sharp compiler. This tutorial assumes it is in your path (my tests were using ‘C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe’)

    Note 2: I recommend you create a temporary folder for the tests and run command line (or powershell) whose current working directory is set to this location, e.g.

    (cmd.exe) C: mkdir \TEMP\CrossPlatformTest cd \TEMP\CrossPlatformTest 

    Step 1: The platform-specific assembly is represented by a simple C# class library:

    // file 'library.cs' in C:\TEMP\CrossPlatformTest namespace Cross.Platform.Library {     public static class Worker     {         public static void Run()         {             System.Console.WriteLine('Worker is running');             System.Console.WriteLine('(Enter to continue)');             System.Console.ReadLine();         }     } } 

    Step 2: We compile platform-specific assemblies using simple command-line commands:

    (cmd.exe from Note 2) mkdir platform\x86 csc /out:platform\x86\library.dll /target:library /platform:x86 library.cs mkdir platform\amd64 csc /out:platform\amd64\library.dll /target:library /platform:x64 library.cs 

    Step 3: Main program is split into two parts. ‘Bootstrapper’ contains main entry point for the executable and it registers a custom assembly resolver in current appdomain:

    // file 'bootstrapper.cs' in C:\TEMP\CrossPlatformTest namespace Cross.Platform.Program {     public static class Bootstrapper     {         public static void Main()         {             System.AppDomain.CurrentDomain.AssemblyResolve += CustomResolve;             App.Run();         }          private static System.Reflection.Assembly CustomResolve(             object sender,             System.ResolveEventArgs args)         {             if (args.Name.StartsWith('library'))             {                 string fileName = System.IO.Path.GetFullPath(                     'platform\\'                     + System.Environment.GetEnvironmentVariable('PROCESSOR_ARCHITECTURE')                     + '\\library.dll');                 System.Console.WriteLine(fileName);                 if (System.IO.File.Exists(fileName))                 {                     return System.Reflection.Assembly.LoadFile(fileName);                 }             }             return null;         }     } } 

    ‘Program’ is the ‘real’ implementation of the application (note that App.Run was invoked at the end of Bootstrapper.Main):

    // file 'program.cs' in C:\TEMP\CrossPlatformTest namespace Cross.Platform.Program {     public static class App     {         public static void Run()         {             Cross.Platform.Library.Worker.Run();         }     } } 

    Step 4: Compile the main application on command line:

    (cmd.exe from Note 2) csc /reference:platform\x86\library.dll /out:program.exe program.cs bootstrapper.cs 

    Step 5: We’re now finished. The structure of the directory we created should be as follows:

    (C:\TEMP\CrossPlatformTest, root dir)     platform (dir)         amd64 (dir)             library.dll         x86 (dir)             library.dll     program.exe     *.cs (source files) 

    If you now run program.exe on a 32bit platform, platform\x86\library.dll will be loaded; if you run program.exe on a 64bit platform, platform\amd64\library.dll will be loaded. Note that I added Console.ReadLine() at the end of the Worker.Run method so that you can use task manager/process explorer to investigate loaded DLLs, or you can use Visual Studio/Windows Debugger to attach to the process to see the call stack etc.

    When program.exe is run, our custom assembly resolver is attached to current appdomain. As soon as .NET starts loading the Program class, it sees a dependency on ‘library’ assembly, so it tries loading it. However, no such assembly is found (because we’ve hidden it in platform/* subdirectories). Luckily, our custom resolver knows our trickery and based on the current platform it tries loading the assembly from appropriate platform/* subdirectory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two versions of a project. One for Silverlight and one for .NET.
I have two versions of a Windows Forms Application and can't figure for the
Suppose we have two overridden versions of a method. One accepts int as argument
I have to include a (managed) C++/CLI component in one of my ASP.NET projects,
What I have: there are two languages installed: German and English language-versions are managed
I have two versions of a product and am using separate Hg repositories for
I have written a Python module, and I have two versions: a pure Python
We have two version of the same assembly in GAC? I want my client
I am very new to iPhone. I have developed two version of an application
Has anyone heard of this error before: I have a Java 5 application, that

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.