Skip to content

Win32Exception when C# tries to launch executables that use .dll files #5816

@jeremy-deutsch

Description

@jeremy-deutsch

Environment

Run the following in your terminal and copy the results here.

  1. npx react-native --version: 4.12.0
  2. npx react-native run-windows --info:
  System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
    Memory: 5.76 GB / 15.89 GB
  Binaries:
    Node: 12.13.0 - ~\AppData\Local\Temp\yarn--1598140426848-0.5372970318084522\node.CMD
    Yarn: 1.19.1 - ~\AppData\Local\Temp\yarn--1598140426848-0.5372970318084522\yarn.CMD
    npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    react: 16.11.0 => 16.11.0
    react-native: ^0.62.0-0 => 0.62.2
    react-native-windows: ^0.62.0-0 => 0.62.5
  Installed UWP SDKs:
    10.0.17763.0
    10.0.18362.0
  1. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock
    AllowDevelopmentWithoutDevLicense    REG_DWORD    0x1
    AllowAllTrustedApps    REG_DWORD    0x1

(using Visual Studio 2019, tried with Debug and Release build configurations)

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Find a path to a .exe file on your computer that depends on one or more .dll files in its directory. I was building a game launcher, so I've tried this with random games I have on my PC (e.g. Super Crate Box). NOTE: most paths on your PC don't seem to be readable/executable by Native Modules, but a path inside Program Files or Program Files (x86) should be.
  2. In a fresh React Native Windows project with C#, add a C# Native Module to your project with a single method that calls Process.Start() with the path from step 1. Then, call that method from your JS code somehow.

The native module method should look something like this:

// top of the file
using System.Diagnostics;

// in the class
[ReactMethod("launchExe")]
public void LaunchExe()
{
   ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\path\to\my.exe");
   Process.Start(startInfo);
}

Expected Results

Describe what you expected to happen.

I expect the executable to run. Instead, Process.Start() throws the following exception:

System.ComponentModel.Win32Exception: '{Illegal System DLL Relocation}
The system DLL %hs was relocated in memory. The application will not run properly.
The relocation occurred because the DLL %hs occupied an address range reserved for Windows system DLLs. The vendor supplying the DLL should be contacted for a new DLL'

Snack, code example, screenshot, or link to a repository:

Here's a minimal code reproduction: https://github.com/jeremy-deutsch/rnw_dll_repro

It doesn't include a .exe/.dll file combination (it'd be really weird to ask someone to run that). It just asks you to type in a path instead, and runs the .exe file at that path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions