-
I am talking about this example https://dotnetfiddle.net/tR9D3D: var asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(typeof(Program).Module.FullyQualifiedName);
asm.MainModule.ImportReference(typeof(Program)).Resolve(); which prints
This works fine when I run it locally and I have no idea what is different with dotnetfiddle (probably something related to the process or its isolation). Could anybody help to investigate it? Please note that the following example works there fine https://dotnetfiddle.net/XGfVNL: var asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(typeof(System.DateTime).Module.FullyQualifiedName);
asm.MainModule.ImportReference(typeof(System.DateTime)).Resolve(); |
Beta Was this translation helpful? Give feedback.
Answered by
adrianoc
Dec 6, 2022
Replies: 1 comment 4 replies
-
That is strange. One workaround (really ugly) is to pass an assembly resolver that returns that assembly: #define TEST
using System.IO;
using System;
var readerParams = new Mono.Cecil.ReaderParameters();
var resolver = new Mono.Cecil.DefaultAssemblyResolver();
readerParams.AssemblyResolver = resolver;
#if TEST
resolver.ResolveFailure += (sender, args) =>
{
return Mono.Cecil.AssemblyDefinition.ReadAssembly(typeof(Program).Assembly.Location);
};
#endif
var files = Directory.GetFiles(Path.GetDirectoryName(typeof(Program).Assembly.Location));
foreach(var file in files)
Console.WriteLine(file);
#if !TEST
System.Console.WriteLine(System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location));
resolver.AddSearchDirectory(System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location));
#endif
var asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(typeof(Program).Assembly.Location, readerParams);
var resolved = asm.MainModule.ImportReference(typeof(Program)).Resolve();
System.Console.WriteLine(resolved); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
Serg046
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is strange.
One workaround (really ugly) is to pass an assembly resolver that returns that assembly: