Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Properly resolve local assemblies.
Browse files Browse the repository at this point in the history
  • Loading branch information
eusebiu authored and dgrunwald committed Aug 28, 2011
1 parent 6cac9f6 commit 5dab783
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 227 deletions.
1 change: 0 additions & 1 deletion src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
Expand Up @@ -64,7 +64,6 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="DebuggerDecompilerService.cs" /> <Compile Include="DebuggerDecompilerService.cs" />
<Compile Include="LaunchILSpy\Fusion.cs" />
<Compile Include="LaunchILSpy\ILSpyAssemblyResolver.cs" /> <Compile Include="LaunchILSpy\ILSpyAssemblyResolver.cs" />
<Compile Include="NavigateToDecompiledEntityService.cs" /> <Compile Include="NavigateToDecompiledEntityService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
216 changes: 0 additions & 216 deletions src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/Fusion.cs

This file was deleted.

Expand Up @@ -8,6 +8,7 @@
using System.Text; using System.Text;


using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using Mono.Cecil; using Mono.Cecil;


namespace ICSharpCode.ILSpyAddIn.LaunchILSpy namespace ICSharpCode.ILSpyAddIn.LaunchILSpy
Expand All @@ -16,6 +17,7 @@ class ILSpyAssemblyResolver : IAssemblyResolver
{ {
readonly DirectoryInfo directoryInfo; readonly DirectoryInfo directoryInfo;
readonly IDictionary<string, AssemblyDefinition> cache; readonly IDictionary<string, AssemblyDefinition> cache;
readonly IDictionary<string, AssemblyDefinition> localAssembliesCache;


public ILSpyAssemblyResolver(string decompiledAssemblyFolder) public ILSpyAssemblyResolver(string decompiledAssemblyFolder)
{ {
Expand All @@ -25,6 +27,9 @@ public ILSpyAssemblyResolver(string decompiledAssemblyFolder)
FolderPath = decompiledAssemblyFolder; FolderPath = decompiledAssemblyFolder;
this.directoryInfo = new DirectoryInfo(decompiledAssemblyFolder); this.directoryInfo = new DirectoryInfo(decompiledAssemblyFolder);
this.cache = new Dictionary<string, AssemblyDefinition> (); this.cache = new Dictionary<string, AssemblyDefinition> ();
this.localAssembliesCache = new Dictionary<string, AssemblyDefinition>();

ReadLocalAssemblies();
} }


public string FolderPath { public string FolderPath {
Expand All @@ -49,13 +54,9 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p
if (cache.TryGetValue(name.FullName, out assembly)) if (cache.TryGetValue(name.FullName, out assembly))
return assembly; return assembly;


// serach into assemblyDecompiledFolder // search into assemblyDecompiledFolder
var file = this.directoryInfo.GetFiles() if (localAssembliesCache.ContainsKey(name.FullName)) {
.Where(f => f != null && f.FullName.Contains(name.Name)) assembly = localAssembliesCache[name.FullName];
.FirstOrDefault();

if (file != null) {
assembly = AssemblyDefinition.ReadAssembly(file.FullName, parameters);
} }


if (assembly == null) { if (assembly == null) {
Expand All @@ -72,7 +73,7 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p
} }
return assembly; return assembly;
} catch (Exception ex) { } catch (Exception ex) {
LoggingService.Error("Exception: " + ex.Message); LoggingService.Error("Exception (ILSpyAssemblyResolver): " + ex.Message);
return null; return null;
} }
} }
Expand All @@ -90,6 +91,19 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
return Resolve(AssemblyNameReference.Parse(fullName), parameters); return Resolve(AssemblyNameReference.Parse(fullName), parameters);
} }


void ReadLocalAssemblies()
{
// read local assemblies
foreach (var file in this.directoryInfo.GetFiles()) {
try {
var localAssembly = AssemblyDefinition.ReadAssembly(file.FullName);
localAssembliesCache.Add(localAssembly.FullName, localAssembly);
} catch {
// unable to read assembly file
}
}
}

#region FindAssemblyInGac #region FindAssemblyInGac
// This region is based on code from Mono.Cecil: // This region is based on code from Mono.Cecil:


Expand Down Expand Up @@ -118,7 +132,7 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //


static readonly string[] gac_paths = { Fusion.GetGacPath(false), Fusion.GetGacPath(true) }; static readonly string[] gac_paths = { GacInterop.GacRootPathV2, GacInterop.GacRootPathV4 };
static readonly string[] gacs = { "GAC_MSIL", "GAC_32", "GAC" }; static readonly string[] gacs = { "GAC_MSIL", "GAC_32", "GAC" };
static readonly string[] prefixes = { string.Empty, "v4.0_" }; static readonly string[] prefixes = { string.Empty, "v4.0_" };


Expand Down
Expand Up @@ -146,7 +146,7 @@ void DecompilationThread()
AnalyticsMonitorService.TrackException(ex); AnalyticsMonitorService.TrackException(ex);


StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.WriteLine("Exception while decompiling " + fullTypeName); writer.WriteLine(string.Format("Exception while decompiling {0} ({1})", fullTypeName, assemblyFile));
writer.WriteLine(); writer.WriteLine();
writer.WriteLine(ex.ToString()); writer.WriteLine(ex.ToString());
WorkbenchSingleton.SafeThreadAsyncCall(OnDecompilationFinished, writer); WorkbenchSingleton.SafeThreadAsyncCall(OnDecompilationFinished, writer);
Expand Down

0 comments on commit 5dab783

Please sign in to comment.