Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-managed dll in Managed folder causes preloader crash #101

Closed
BlueAmulet opened this issue Nov 12, 2019 · 2 comments
Closed

non-managed dll in Managed folder causes preloader crash #101

BlueAmulet opened this issue Nov 12, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@BlueAmulet
Copy link

Describe the bug
If a non-managed dll exists within the managed path, the preloader crashes with an accurate but unhelpful "System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid." message.

To Reproduce
Place any non-managed dll within a game's Managed folder

Expected behavior
The preloader to skip non-managed dll's, or handle the error better

Screenshots and logs

[Fatal  :   BepInEx] Could not run preloader!
[Fatal  :   BepInEx] System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
  at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders (System.UInt16& subsystem, System.UInt16& dll_characteristics) [0x000bb] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.PE.ImageReader.ReadImage () [0x0008b] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.PE.ImageReader.ReadImage (Mono.Disposable`1[T] stream, System.String file_name) [0x00007] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (Mono.Disposable`1[T] stream, System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00006] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x0006c] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) [0x00007] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName) [0x00000] in <02cd44f94ebd4355b3be9e1dbd9d77a1>:0
  at BepInEx.Preloader.Patching.AssemblyPatcher.PatchAndLoad (System.String directory) [0x0001e] in <f7eb2f9c7412463299cd6eea6a3d029d>:0
  at BepInEx.Preloader.Preloader.Run () [0x001f4] in <f7eb2f9c7412463299cd6eea6a3d029d>:0

Desktop (please complete the following information):

  • Game and game version: Issue is not game specific
  • BepInEx version: 5.0.0.171

Additional context
I've encountered this issue in a couple of games downloaded from Steam where additional dlls existed within the Managed folder, it's easy enough to detect and remove them but it would be better if the preloader could handle this situation better.

@bbepis
Copy link
Member

bbepis commented Nov 12, 2019

Thanks for identifying this. It's related to the Mono.Cecil speculative loader not being able to handle unmanaged DLLs, unlike the old type loader implementation.
Will be fixed in v5.1.

@bbepis bbepis added the bug Something isn't working label Nov 12, 2019
@bbepis bbepis self-assigned this Nov 12, 2019
@ghorsington
Copy link
Contributor

If you want to use BepInEx in games with unmanaged assemblies in Managed folder before 5.1, please download bleeding edge build of BepInEx. Build 173 and newer should include the required fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants