Missing default AssemblyResolver on .NET Core
See original GitHub issueI 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:
- Created 7 years ago
- Comments:14 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Fixed in #444.
@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:
(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! 💘)