How can I conditionally run my program in 64-bit or 32-bit mode based on external resources?

All forums have several questions (and unwanted answers) that the provider is Microsoft.ACE.OLEDB.12.0not registered on the local computer, for example this one . The essence of the problem, as I understand it, is that the application will look for a provider on the same platform as the application. Therefore, if your computer has a 64-bit bit and a 32-bit provider, then there will be a discrepancy if you do not compile the application to work in 32-bit mode.

Most of the answers do this effectively by installing the appropriate data components for the current platform. Other suggestions are compiling for any platform in which data components are available.

I am developing an application using a PC running Windows 7, 8, and 10, all 64 bits, depending on where I am, but some of them have older versions of Office and other newer versions. This forces me to change the platform for which I am compiling, depending on which I am currently working on. Although this is not a problem for me, personally, I predict that it causes headaches for end users who cannot run the program.

An attempt not to ask users to install other components on their computers; Is there a way I can tell the program to check the availability of the database provider platform and then run in this mode? Is it possible to create 32-bit and 64-bit extensions of the database module and load the corresponding file regardless of the mode in which the main program works?

EDIT:

I just tried to compile my database extensions on different platforms. Whichever option is the same platform as the application, it throws an exception when loading, saying that I am trying to download the assembly from another platform. So I think I was out of luck with my option 2 ...

+4
source share
1

CorFlags , , .

, exe Prefer 32 bit, . , , , 64- , ( - OLEDB). (, 64- , 32-) - , , . - cmd script, ( exe ConsoleApplication3.exe):

:start
start /wait "" "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\CorFlags.exe" ConsoleApplication3.exe /32BIT+
if errorlevel 1 (
    goto start
)
start "" ConsoleApplication3.exe

, , - , , . script , exe, CorFlags 32- , exe.

:

static void Main() {
    if (Environment.Is64BitProcess) {
        // here you also check if you have dependency mismatch, and then:
        Console.WriteLine("Running in 64-bit mode. Press any key to fix");
        Console.ReadKey();
        // run script (here we assume script is in the same directory as main executable, and is called fix-mode.cmd
        var process = new Process() {
            StartInfo = new ProcessStartInfo("cmd.exe", "/c call fix-mode.cmd")
        };
        process.Start();                
        // here you should exit your application immediatly, so that CorFlags can update it (since it cannot do that while it is running)
    }
    else {
        // after restart by our script - we will get here
        Console.WriteLine("Running in 32bit mode");
    }
}

, (CorFlags) Visual Studio, ( ).

+1

All Articles