ModuleDefinition.Assembly is null in multi-module assemblies #652

Closed
opened 2020-02-21 04:35:43 -06:00 by sajagi · 3 comments
sajagi commented 2020-02-21 04:35:43 -06:00 (Migrated from github.com)

I am not sure whether this qualifies as a bug or is it intentional. ModuleDefinition.Assembly property in AssemblyDefinition.Modules is null for modules which are not defined in the same dll as the assembly. Given that the the assembly definition always creates new instances of module definitions it would make sense to keep the link back to the assembly.

public void Test()
{
    var module = ModuleDefinition.ReadModule(@"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.EnterpriseServices.dll");
    
    foreach (var m in module.Assembly.Modules)
        Console.WriteLine($"{m.Name} assembly: {m.Assembly?.Name.Name ?? "null"}");

    // prints: 
    // System.EnterpriseServices.dll assembly: System.EnterpriseServices
    // System.EnterpriseServices.Wrapper.dll assembly: null
}

The problem with current situation is that currently there is no way to associate TypeDefinitions in such auxiliary modules back to the assembly they were defined in.

Thanks for your hard work!

I am not sure whether this qualifies as a bug or is it intentional. `ModuleDefinition.Assembly` property in `AssemblyDefinition.Modules` is `null` for modules which are not defined in the same dll as the assembly. Given that the the assembly definition always creates new instances of module definitions it would make sense to keep the link back to the assembly. ```csharp public void Test() { var module = ModuleDefinition.ReadModule(@"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.EnterpriseServices.dll"); foreach (var m in module.Assembly.Modules) Console.WriteLine($"{m.Name} assembly: {m.Assembly?.Name.Name ?? "null"}"); // prints: // System.EnterpriseServices.dll assembly: System.EnterpriseServices // System.EnterpriseServices.Wrapper.dll assembly: null } ``` The problem with current situation is that currently there is no way to associate TypeDefinitions in such auxiliary modules back to the assembly they were defined in. Thanks for your hard work!
jbevain commented 2020-02-21 11:35:32 -06:00 (Migrated from github.com)

I think the original intent was that there's no Assembly row in a multi-module assembly.
So in theory, a multi module assembly could even belong to 2 assemblies.
Also I like to pretend that multi-module don't really exist :)

I think the original intent was that there's no Assembly row in a multi-module assembly. So in theory, a multi module assembly could even belong to 2 assemblies. Also I like to pretend that multi-module don't really exist :)
jbevain commented 2021-03-15 18:49:45 -05:00 (Migrated from github.com)

I think the way to go would be:

If you use AssemblyDefinition.ReadAssembly on a multi-module assembly, the .Assembly property should return the main assembly.
If you use ModuleDefinition.ReadModule on a .netmodule, the .Assembly property should return null.

I think the way to go would be: If you use `AssemblyDefinition.ReadAssembly` on a multi-module assembly, the `.Assembly` property should return the main assembly. If you use `ModuleDefinition.ReadModule` on a `.netmodule`, the `.Assembly` property should return null.
jbevain commented 2021-04-23 16:46:39 -05:00 (Migrated from github.com)

Fixed by #730

Fixed by #730
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#652
No description provided.