question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing default AssemblyResolver on .NET Core

See original GitHub issue

I have essentially the following program:

var module = ModuleDefinition.ReadModule(moduleName);
var type = module.Types.Single(ti => ti.FullName == typeName);
var method = type.Methods.Single(mi => mi.Name == methodName);
foreach (var instr in method.Body.Instructions) {
    switch (instr.OpCode.Code) {
        case Code.Call: {
            var mref = instr.Operand as MethodReference;
            var mdef = mref.Resolve();
        }
    }
}

This works fine in Mono, but gives an ArgumentNullException running in .NET Core (Linux) when calling mref.Resolve(). Stacktrace is

System.ArgumentNullException : Value cannot be null.
Parameter name: assemblyResolver
   at Mono.Cecil.MetadataResolver..ctor(IAssemblyResolver assemblyResolver)
   at Mono.Cecil.ModuleDefinition.get_MetadataResolver()
   at Mono.Cecil.ModuleDefinition.Resolve(MethodReference method)
   at ...

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jbevaincommented, Oct 25, 2017

Fixed in #444.

0reactions
per-samuelssoncommented, Oct 3, 2017

@jbevain

I might be missing something essential here, but I just can’t see how the custom resolver posted earlier could have ever worked.

Basing it on DependencyContext.Default.CompileLibraries, will that not resolve to libraries of the current application? And if so, how often would you want to resolve references based on that?

I’m guessing “all” Cecil consumers would work on a given input assembly, and for that to work, resolving must be based on that, no?

If you’d ever find time to reflect on that, could you also comment on the status of this:

Good catch, we do not have a default assembly resolver for .NET Core. That’s something we need to fix.

(And just to make sure I’m not only coming here bringing pain: I really love Cecil; its code-base, the design, and the straightforwardness in using it - big props! 💘)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve references of a .NET assembly from a .Net ...
Solution is to either set the target framework of the tool to .NET Framework or to write your own assembly resolver. I think...
Read more >
Resolve assembly loads
This article describes the .NET AppDomain.AssemblyResolve event. Use this event for applications that require control over assembly loading.
Read more >
Deep-dive into .NET Core primitives: deps.json ...
I learned to program with gcc, C++, and vim. When I started working with C# and .NET, clicking the “Start” button in Visual...
Read more >
Resolving Assemblies in .NET Core
I needed to reflect over the types defined in an external assembly in order to look for specific attributes. The first problem is...
Read more >
Assembly Versioning and DLL Hell in C# .NET Framework
AssemblyResolve event is fired when an assembly fails to load. This might happen when the same assembly of a different version is already...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found