private static Assembly LoadFromGacOrAppDir(AssemblyQuery q) { if (!q.IsPartialName) throw new AssemblyNotFoundException( q.Query + " is not a valid assembly name (it should NOT end with " + AssemblyQuery.ASSEMBLY_EXTENSION + ")" ); Assembly a = null; try { a = Assembly.Load(q.ToAssemblyName()); return a; } catch (Exception err) { try { // try to load it from the current application directory string assemblyPath = Path.Combine(Location.ApplicationDirectory, q.Query + AssemblyQuery.ASSEMBLY_EXTENSION); a = Assembly.LoadFrom(assemblyPath); return a; } catch(Exception e) { #if COMPACT throw new AssemblyNotFoundException(q.Query, e); #else // if all else failed, try LoadWithPartialName. This is // necessary for GTK# on Windows since it only provides // .NET 1.0 versions which are not found by Assembly.Load // on .NET 2.0. a = Assembly.LoadWithPartialName(q.Query); if (a != null) return a; else throw new AssemblyNotFoundException(q.Query, e); #endif } } }