none
Assembly.LoadFrom() stopped working in application on windows 8 RRS feed

  • Question

  • I am using Assembly Resolve to catch in the appdomain, and then using Assembly.LoadFrom() to load them up from a subfolder of my application called Libraries.  This allows my dynamic upgrade ability where I can allow users to download only necessary parts that are updated.

    I have coded in .Net 2.0 and VS2012 currently.  It has worked great for years.. until recently I tested on Windows 8 and it blows up unable to Resolve the libraries.  If I install the 3rd party libraries to the GAC it works great... but that is not really an option for client pcs.

    Any ideas, help?

    Code is similar to the example found at (see below): http://www.albahari.com/nutshell/ch16.aspx

    Deploying assemblies outside the base folder:

    using System;
    using System.IO;
    using System.Reflection;
    
    public class Loader
    {
      static void Main()
      {
        AppDomain.CurrentDomain.AssemblyResolve += FindAssem;
    
        // We must switch to another class before attempting to use
        // any of the types in c:\ExtraAssemblies:
        Program.Go();
      }
    
      static Assembly FindAssem (object sender, ResolveEventArgs args)
      {
        string simpleName = new AssemblyName (args.Name).Name;
        string path = @"c:\ExtraAssemblies\" + simpleName + ".dll";
        
        if (!File.Exists (path)) return null;     // Sanity check
        return Assembly.LoadFrom (path);          // Load it up!
      }
    }
    
    public class Program
    {
      public static void Go()
      {
        // Now we can reference types defined in c:\ExtraAssemblies
      }
    }

    Thursday, April 11, 2013 3:54 AM

Answers

  • I figured out that I had to extrapolate it to another class.  Prior, I was subscribing to assembly resolve on the current appdomain in the program main.  This worked fine up until windows 8, then it started to get sassy.

    Moving it out to another class that runs first fixed my issue.

    Thursday, April 11, 2013 4:56 PM

All replies

  • This short code seems to work well in Windows 8. I suggest to try a similar simple fragment on your machine, maybe using a different disk to avoid permission issues.

    Thursday, April 11, 2013 5:55 AM
  • I figured out that I had to extrapolate it to another class.  Prior, I was subscribing to assembly resolve on the current appdomain in the program main.  This worked fine up until windows 8, then it started to get sassy.

    Moving it out to another class that runs first fixed my issue.

    Thursday, April 11, 2013 4:56 PM