Repository navigation
Merge in changes from upstream - #505
Merged
Merged
Conversation
In the .NET world, executable assemblies have a Foo.exe and Foo.dll file. Foo.exe is not a managed assembly and attempt to load it will cause ``` System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid. at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics) in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil.PE\ImageReader.cs:line 198 at Mono.Cecil.PE.ImageReader.ReadImage() in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil.PE\ImageReader.cs:line 86 at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil.PE\ImageReader.cs:line 766 at Mono.Cecil.ModuleDefinition.ReadModule(Disposable`1 stream, String fileName, ReaderParameters parameters) in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil\ModuleDefinition.cs:line 1141 at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil\ModuleDefinition.cs:line 1110 at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters) in C:\UnitySrc\dev\il2cpp-18\external\cecil\Mono.Cecil\AssemblyDefinition.cs:line 132 ``` By attempting to locate `.dll` files before `.exe` this problem can be avoided. For context, I hit this in one of our resolvers while attempting to resolve all of the dependencies of an executable that referenced another executable. I fixed our resolver the same way but noticed `BaseAssemblyResolver` had the same behavior we had so I thought I'd upstream the change.
…flection.Metadata (jbevain#958) * Fix WriteCompressedInt32 logic by using the same code as in System.Reflection.Metadata Note: the implementation in SRM uses methods that are not available in netfx 4.0. To make the code work with all platforms supported by Mono.Cecil, I extracted the required methods. * Cleanup whitespaces --------- Co-authored-by: Jb Evain <jb@evain.net>
* Fixed: SymWriter COM object is not released on exception The Problem: Problem observed when being used in coverlet: coverlet-coverage/coverlet#1471 If an exception caused `NativePdbWriter.Write` to never be called, it would not call `SymWriter.Close`, which in turn meant `Marshal.ReleaseComObject` was left uncalled. The garbage collector will eventually destroy the object and thereby release the COM object, but that happens non-deterministically. The COM object is holding to a file handle, which prevents other operations on the written file until it is released. The result was random file access issues. The Solution: Luckily NativePdbWriter is IDisposable. I added a call to `writer.Close` there. But now it could be called twice, so I had to add a boolean to SymWriter to avoid releasing everything twice. * Code style --------- Co-authored-by: Jb Evain <jb@evain.net>
* Preserve custom debug info on types * Use ICustomDebugInformationProvider in ISymbolReader/ISymbolWriter * Move get logic to Mixin helpers * Add test dll/pdb * PR feedback - Use static lambdas - Check HasCustomDebugInformation - Test writing modified CustomDebugInformation - Formatting fixes * Update Test/Mono.Cecil.Tests/PortablePdbTests.cs Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> * Build for netstandard2.0 --------- Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
* Protect against circular type forwarders If we have two assemblies with type forwarders that point to each other, we enter an infinite loop and a stack overflow. This breaks the cycle by detecting reentrancy. Fixes jbevain#706 * Add a test for TypeForwardedTo circularity * Move field up
* Preserve Documents * Target net6.0 To remove reference to RefSafetyRulesAttribute * Target .NET Framework To avoid references to System.Runtime
agocke
approved these changes
Aug 11, 2026
This was referenced Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To pick up the fix from jbevain#958 (see #504 for context).