Skip to content

[DirectoryAssemblyResolver] add GetAssembly () that allows to set R… #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public IDictionary ToResolverCache ()
return resolver_cache;
}

public virtual AssemblyDefinition Load (string fileName)
public virtual AssemblyDefinition Load (string fileName, ReaderParameters parameters = null)
{
if (!File.Exists (fileName))
return null;
Expand All @@ -104,29 +104,28 @@ public virtual AssemblyDefinition Load (string fileName)
return assembly;

try {
assembly = ReadAssembly (fileName);
assembly = ReadAssembly (fileName, parameters);
} catch (Exception e) {
Diagnostic.Error (9, e, "Error while loading assembly: {0}", fileName);
}
cache.Add (name, assembly);
return assembly;
}

protected virtual AssemblyDefinition ReadAssembly (string file)
protected virtual AssemblyDefinition ReadAssembly (string file, ReaderParameters parameters)
{
var reader_parameters = new ReaderParameters () {
AssemblyResolver = this,
ReadSymbols = loadDebugSymbols && (File.Exists(file + ".mdb") || File.Exists(Path.ChangeExtension(file, ".pdb"))),
};
parameters = parameters ?? new ReaderParameters ();
parameters.AssemblyResolver = this;
parameters.ReadSymbols = loadDebugSymbols && (File.Exists(file + ".mdb") || File.Exists(Path.ChangeExtension(file, ".pdb")));
try {
return AssemblyDefinition.ReadAssembly (file, reader_parameters);
return AssemblyDefinition.ReadAssembly (file, parameters);
} catch (Exception ex) {
logWarnings (
"Failed to read '{0}' with debugging symbols. Retrying to load it without it. Error details are logged below.",
new [] { file });
logWarnings ("{0}", new [] { ex.ToString () });
reader_parameters.ReadSymbols = false;
return AssemblyDefinition.ReadAssembly (file, reader_parameters);
parameters.ReadSymbols = false;
return AssemblyDefinition.ReadAssembly (file, parameters);
}
}

Expand All @@ -135,6 +134,11 @@ public AssemblyDefinition GetAssembly (string fileName)
return Resolve (Path.GetFileNameWithoutExtension (fileName));
}

public AssemblyDefinition GetAssembly (string fileName, ReaderParameters parameters)
{
return Resolve (Path.GetFileNameWithoutExtension (fileName), parameters);
}

public AssemblyDefinition Resolve (string fullName)
{
return Resolve (fullName, null);
Expand Down Expand Up @@ -187,7 +191,7 @@ public AssemblyDefinition Resolve (AssemblyNameReference reference, ReaderParame
AssemblyDefinition candidate = null;
foreach (var dir in SearchDirectories) {
if ((assemblyFile = SearchDirectory (name, dir)) != null) {
var loaded = Load (assemblyFile);
var loaded = Load (assemblyFile, parameters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewurm did you miss adding 'ReaderParameters parameters' on line 147?
also we can make use of
public virtual AssemblyDefinition Load (string fileName, ReaderParameters parameters = null)
so we don't need to duplicate the Load method same for ReadAssembly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, there's already a version with ReaderParameters on line 152.
thanks for the hint about default parameter values, I'll change that.

if (Array.Equals (loaded.Name.MetadataToken, reference.MetadataToken))
return loaded;
candidate = candidate ?? loaded;
Expand Down