So should we remove the code then? If so, the attached patch should do
it.
Thanks,
- Jon
On Thu, 2009-04-30 at 22:19 +0200, Pascal Craponne wrote:
> It is never used, if I remember well.
>
>
> On Thu, Apr 30, 2009 at 22:13, Jonathan Pryor <[email protected]> wrote:
>
> For mostly unrelated reasons (due to a bad configuration), I
> found myself digging through
> src/DbMetal/Generator/Implementation/SchemaLoaderFactory.cs,
> specifically
> SchemaLoaderFactory.CurrentDomain_AssemblyResolve(), and found
> myself wondering...what's going on?
>
> Specifically, it appears to contain code which will probe the
> current working directory for assemblies that couldn't be
> found. Thus, the questions:
>
> 1. Is this really necessary?
>
> 2. The current working directory? Seriously? Keep in mind
> that DbMetal.exe is a command-line app; thus, with the current
> logic it'll probe whatever directory you happen to be in when
> running the app. This seems decidedly counter-intuitive, as
> merely changing your directory will either fix or cause
> problems.
>
> It would seem more rational to probe DbMetal.exe's
> directory...but that's what Type.GetType() already does.
>
> 3. It assumes where the GAC is -- %SystemRoot%\Assembly\GAC,
> etc. Aside from the obvious that this won't work on Mono,
> this relies on an implementation detail of .NET which could
> change at any time.
>
> For the Mono case, the "workaround" is to just never hit that
> code path in the first place (i.e. provide a correct fully
> qualified type name), so this isn't a major problem. It's
> just a "wtf?!" moment, something I'd prefer to have fewer
> of...
>
> Thanks,
> - Jon
>
>
>
>
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: src/DbMetal/Generator/Implementation/SchemaLoaderFactory.cs
===================================================================
--- src/DbMetal/Generator/Implementation/SchemaLoaderFactory.cs (revision 1062)
+++ src/DbMetal/Generator/Implementation/SchemaLoaderFactory.cs (working copy)
@@ -130,7 +130,6 @@
public ISchemaLoader Load(Parameters parameters, string dbLinqSchemaLoaderTypeName, string databaseConnectionTypeName)
{
- AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Type dbLinqSchemaLoaderType = Type.GetType(dbLinqSchemaLoaderTypeName);
Type databaseConnectionType = Type.GetType(databaseConnectionTypeName);
@@ -140,92 +139,9 @@
throw new ArgumentException("Unable to resolve databaseConnectionType: " + databaseConnectionTypeName);
ISchemaLoader loader = Load(parameters, dbLinqSchemaLoaderType, databaseConnectionType);
- AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
return loader;
}
- private Assembly LoadAssembly(string path)
- {
- if (File.Exists(path))
- return Assembly.LoadFile(path);
- return null;
- }
-
- private Assembly LoadAssembly(string baseName, string path)
- {
- string basePath = Path.Combine(path, baseName);
- Assembly assembly = LoadAssembly(basePath + ".dll");
- if (assembly == null)
- assembly = LoadAssembly(basePath + ".exe");
- return assembly;
- }
-
- private Assembly LocalLoadAssembly(string baseName)
- {
- Assembly assembly = LoadAssembly(baseName, Directory.GetCurrentDirectory());
- if (assembly == null)
- assembly = LoadAssembly(baseName, new Uri(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase)).LocalPath);
- return assembly;
- }
-
- private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
- {
- // try to load from within the current AppDomain
- IList<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
- foreach (Assembly loadedAssembly in assemblies)
- {
- if (loadedAssembly.GetName().Name == args.Name)
- return loadedAssembly;
- }
- var assembly = LocalLoadAssembly(args.Name);
- if (assembly == null)
- assembly = GacLoadAssembly(args.Name);
- return assembly;
- }
-
- /// <summary>
- /// This is dirty, and must not be used in production environment
- /// </summary>
- /// <param name="shortName"></param>
- /// <returns></returns>
- private Assembly GacLoadAssembly(string shortName)
- {
- var systemRoot = Environment.GetEnvironmentVariable("SystemRoot");
- string assemblyDirectory = Path.Combine(systemRoot, "Assembly");
- var assembly = GacLoadAssembly(shortName, Path.Combine(assemblyDirectory, "GAC_MSIL"));
- if (assembly == null)
- assembly = GacLoadAssembly(shortName, Path.Combine(assemblyDirectory, "GAC_32"));
- if (assembly == null)
- assembly = GacLoadAssembly(shortName, Path.Combine(assemblyDirectory, "GAC"));
- return assembly;
- }
-
- private Assembly GacLoadAssembly(string shortName, string directory)
- {
- string assemblyDirectory = Path.Combine(directory, shortName);
- if (Directory.Exists(assemblyDirectory))
- {
- Version latestVersion = null;
- string latestVersionDirectory = null;
- foreach (string versionDirectory in Directory.GetDirectories(assemblyDirectory))
- {
- var testVersion = new Version(Path.GetFileName(versionDirectory).Split('_')[0]);
- if (latestVersion == null || testVersion.CompareTo(latestVersion) > 0)
- {
- latestVersion = testVersion;
- latestVersionDirectory = versionDirectory;
- }
- }
- if (latestVersionDirectory != null)
- {
- string assemblyPath = Path.Combine(latestVersionDirectory, shortName + ".dll");
- if (File.Exists(assemblyPath))
- return Assembly.LoadFile(assemblyPath);
- }
- }
- return null;
- }
-
protected void GetLoaderAndConnection(out string dbLinqSchemaLoaderType, out string databaseConnectionType, string provider)
{
var configuration = (ProvidersSection)ConfigurationManager.GetSection("providers");