Here is my code to open the assembly:
private void LoadAssembly()
{
var resolver = new DefaultAssemblyResolver();
if (string.IsNullOrEmpty(SourceAssemblyFolder) == false)
resolver.AddSearchDirectory(SourceAssemblyFolder);
var parameters = new ReaderParameters
{
SymbolReaderProvider = new PdbReaderProvider(),
ReadingMode = ReadingMode.Immediate,
AssemblyResolver = resolver,
};
try
{
ModuleDefinition =
ModuleDefinition.ReadModule(SourceAssemblyFileName, parameters);
pdbFileLoaded = true;
}
catch (Exception)
{
// if we cannot read the symbols we should ignore
them.
parameters.SymbolReaderProvider = null;
ModuleDefinition =
ModuleDefinition.ReadModule(SourceAssemblyFileName, parameters);
}
}
And here how i get the first available file name for a type:
public string FindFileName(TypeDefinition typedef)
{
if (HasDebugInfo)
{
foreach (var method in typedef.Methods)
{
if (method.Body != null &&
method.Body.Instructions != null)
{
foreach (var instruction in
method.Body.Instructions)
{
if (instruction.SequencePoint != null &&
instruction.SequencePoint.Document != null &&
instruction.SequencePoint.Document.Url != null)
return
instruction.SequencePoint.Document.Url;
}
}
}
}
return null;
}
Jan
--
--
mono-cecil