Exemplo n.º 1
0
        private AssemblyAndLocation ShadowCopyAndLoadAndAddEntry(string originalPath, out AssemblyLoadResult result, bool explicitLoad)
        {
            AssemblyAndLocation assemblyAndLocation = ShadowCopyAndLoad(originalPath);

            if (assemblyAndLocation.IsDefault)
            {
                result = default(AssemblyLoadResult);
                return(default(AssemblyAndLocation));
            }

            lock (_referencesLock)
            {
                // Always remember the path. The assembly might have been loaded from another path or not loaded yet.
                _assembliesLoadedFromLocationByFullPath[originalPath] = assemblyAndLocation;

                LoadedAssembly loadedAssembly;
                if (_assembliesLoadedFromLocation.TryGetValue(assemblyAndLocation.Assembly, out loadedAssembly))
                {
                    // The same assembly may have been loaded from a different path already,
                    // or the assembly has been loaded while we were copying the file and loading the copy;
                    // Use the existing assembly record.
                    if (loadedAssembly.LoadedExplicitly)
                    {
                        result = AssemblyLoadResult.CreateAlreadyLoaded(assemblyAndLocation.Location, loadedAssembly.OriginalPath);
                    }
                    else
                    {
                        loadedAssembly.LoadedExplicitly = explicitLoad;
                        result = AssemblyLoadResult.CreateSuccessful(assemblyAndLocation.Location, loadedAssembly.OriginalPath);
                    }

                    return(assemblyAndLocation);
                }
                else
                {
                    result = AssemblyLoadResult.CreateSuccessful(
                        assemblyAndLocation.Location,
                        assemblyAndLocation.GlobalAssemblyCache ? assemblyAndLocation.Location : originalPath);

                    _assembliesLoadedFromLocation.Add(
                        assemblyAndLocation.Assembly,
                        new LoadedAssembly {
                        LoadedExplicitly = explicitLoad, OriginalPath = result.OriginalPath
                    });
                }

                RegisterLoadedAssemblySimpleNameNoLock(assemblyAndLocation.Assembly);
            }

            if (_shadowCopyProvider != null && assemblyAndLocation.GlobalAssemblyCache)
            {
                _shadowCopyProvider.SuppressShadowCopy(originalPath);
            }

            return(assemblyAndLocation);
        }
Exemplo n.º 2
0
        private Assembly ShadowCopyAndLoadAndAddEntry(string originalPath, out AssemblyLoadResult result, bool explicitLoad)
        {
            Assembly assembly = ShadowCopyAndLoad(originalPath);

            if (assembly == null)
            {
                result = default(AssemblyLoadResult);
                return(null);
            }

            lock (ReferencesLock)
            {
                // Always remember the path. The assembly might have been loaded from another path or not loaded yet.
                _loadedAssembliesByPath[originalPath] = assembly;

                LoadedAssembly loadedAssembly;
                if (_loadedAssemblies.TryGetValue(assembly, out loadedAssembly))
                {
                    // The assembly has been loaded while we were copying the file and loading the copy;
                    // Ignore the copy (unfortunately we can't unload a loaded assembly) and use the
                    // existing one.
                    if (loadedAssembly.LoadedExplicitly)
                    {
                        result = AssemblyLoadResult.CreateAlreadyLoaded(assembly.Location, loadedAssembly.OriginalPath);
                    }
                    else
                    {
                        loadedAssembly.LoadedExplicitly = explicitLoad;
                        result = AssemblyLoadResult.CreateSuccessful(assembly.Location, loadedAssembly.OriginalPath);
                    }

                    return(assembly);
                }
                else
                {
                    result = AssemblyLoadResult.CreateSuccessful(assembly.Location, assembly.GlobalAssemblyCache ? assembly.Location : originalPath);
                    _loadedAssemblies.Add(assembly, new LoadedAssembly {
                        LoadedExplicitly = explicitLoad, OriginalPath = result.OriginalPath
                    });
                }

                RegisterLoadedAssemblySimpleNameNoLock(assembly);
            }

            if (_shadowCopyProvider != null && assembly.GlobalAssemblyCache)
            {
                _shadowCopyProvider.SuppressShadowCopy(originalPath);
            }

            return(assembly);
        }