Galen.Ci.EntityFramework.AssemblyLoader.ResolveDependentAssembly C# (CSharp) Method

ResolveDependentAssembly() private method

private ResolveDependentAssembly ( object sender, ResolveEventArgs args ) : Assembly
sender object
args System.ResolveEventArgs
return System.Reflection.Assembly
        private Assembly ResolveDependentAssembly(object sender, ResolveEventArgs args)
        {
            MigrationsSource source;

            if (!args.Name.Contains(".resource") && args.RequestingAssembly == null)
            {
                //Ignore resource file requests
                //If we get here, an assembly that we resolved manually is now requesting another assembly
                //In some caes, the RequestingAssembly will be null - but we *should* already have this assembly in memory
                //So just try and retun an existing one.
                return AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.FullName == args.Name);
            }

            if (m_Sources.TryGetValue(BuildAssemblyId(args.RequestingAssembly), out source))
            {
                var assemblyName = new AssemblyName(args.Name);

                string targetPath = Path.Combine(
                    source == MigrationsSource.Deployed ? m_DeployedPath : m_TargetPath, string.Format("{0}.dll", assemblyName.Name));

                assemblyName.CodeBase = targetPath;

                Log.Debug(
                    "Assembly loader {loaderHashCode} searching for dependent assembly {assemblyName} requested by migration sourced from {MigrationsSource} at {targetPath}. Request made by assembly {requestingAssembly}.",
                    this.GetHashCode(), args.Name, source, targetPath, args.RequestingAssembly.CodeBase);

                //We have to use LoadFile here, otherwise we won't load a differing
                //version, regardless of the codebase because only LoadFile
                //will actually load a *new* assembly if it's at a different path
                //See: http://msdn.microsoft.com/en-us/library/b61s44e8(v=vs.110).aspx
                var dependentAssembly = Assembly.LoadFile(assemblyName.CodeBase);
                m_Sources.TryAdd(BuildAssemblyId(dependentAssembly), source);

                Log.Debug(
                    "Assembly loader {loaderHashCode} found ependent assembly {assemblyName} requested by migration sourced from {MigrationsSource} at {targetPath}. Request made by assembly {requestingAssembly}.",
                    this.GetHashCode(), args.Name, source, targetPath, args.RequestingAssembly.CodeBase);

                return dependentAssembly;
            }

            return null;
        }