title: How to download a DLL assembly in VB.Net if it can't be loaded
body: <p>Is it possible to download a *.dll and subsequently load it if it can't be found on the local machine? I am using VB.Net and I can catch the AssemblyResolve event, but I get an exception when I try to use System.Net.WebClient to download the assembly from my web server then load it with Reflection.</p>
  
  <pre><code>AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf downloadAssembly
  
  Private Function downloadAssembly()
  Dim downloader As New System.Net.WebClient()
  downloader.DownloadFile(New Uri("http://path.toserver.com/myassembly.dll"), "myassembly.dll")
  Dim NewAssembly As Reflection.Assembly
  NewAssembly = Reflection.Assembly.LoadFrom("myassembly.dll")
  Return NewAssembly
  End Function
  </code></pre>
  
  <pre>The exception is of type: System.InvalidOperationException
  Problem signature:
    Problem Event Name:   CLR20r3
    Problem Signature 01: wind-x.exe
    Problem Signature 02: 1.0.0.0
    Problem Signature 03: 4f5104ea
    Problem Signature 04: Wind-X
    Problem Signature 05: 1.0.0.0
    Problem Signature 06: 4f5104ea
    Problem Signature 07: 1f
    Problem Signature 08: c6
    Problem Signature 09: System.InvalidOperationException
    OS Version:   6.1.7601.2.1.0.256.4
    Locale ID:    1033
    Additional Information 1: 0a9e
    Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
    Additional Information 3: 0a9e
    Additional Information 4: 0a9e372d3b4ad19135b953a78882e789</pre>