title: ILSpy, how to resolve dependencies?
body: <p>I want to disassemble an entire .NET assembly with ILSpy.</p>
  
  <p>I used this code as base:<br />
  <a href="http://skysigal.xact-solutions.com/Blog/tabid/427/entryid/2488/Default.aspx" rel="nofollow">http://skysigal.xact-solutions.com/Blog/tabid/427/entryid/2488/Default.aspx</a></p>
  
  <p>And it works fine, just when I have an assembly that references Npgsql.dll (or any other non-gac assembly), then I get an AssemblyResolutionException.</p>
  
  <p>Failed to resolve assembly: 'Npgsql, Version=2.0.11.92, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'</p>
  
  <p>I know how I can get the referenced assemblies, but how can I add them to ast ?</p>
  
  <pre><code>    // SqlWebAdmin.Models.Decompiler.DecompileAssembly("xy.dll");
      public static string DecompileAssembly(string pathToAssembly)
      {
          //Assembly assembly = Assembly.LoadFrom(pathToAssembly);
          System.Reflection.Assembly assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(pathToAssembly);
          //assembly.GetReferencedAssemblies();
  
          //assembly.GetReferencedAssemblies(assembly);
          Mono.Cecil.AssemblyDefinition assemblyDefinition =
              Mono.Cecil.AssemblyDefinition.ReadAssembly(pathToAssembly);
  
  
  
          ICSharpCode.Decompiler.Ast.AstBuilder astBuilder = new ICSharpCode.Decompiler.Ast.AstBuilder(new ICSharpCode.Decompiler.DecompilerContext(assemblyDefinition.MainModule));
          astBuilder.AddAssembly(assemblyDefinition);
  
  
          //new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit);
          using (System.IO.StringWriter output = new System.IO.StringWriter())
          {
              astBuilder.GenerateCode(new ICSharpCode.Decompiler.PlainTextOutput(output));
              string result = output.ToString();
              return result;
          }
  
          return "";
      } // End Function DecompileAssembly
  </code></pre>