Ejemplo n.º 1
0
        private AssemblyLoadResult LoadFromPathInternal(string fullPath)
        {
            AssemblyAndLocation assembly;

            lock (_referencesLock)
            {
                if (_assembliesLoadedFromLocationByFullPath.TryGetValue(fullPath, out assembly))
                {
                    LoadedAssembly loadedAssembly = _assembliesLoadedFromLocation[assembly.Assembly];
                    if (loadedAssembly.LoadedExplicitly)
                    {
                        return(AssemblyLoadResult.CreateAlreadyLoaded(assembly.Location, loadedAssembly.OriginalPath));
                    }
                    else
                    {
                        loadedAssembly.LoadedExplicitly = true;
                        return(AssemblyLoadResult.CreateSuccessful(assembly.Location, loadedAssembly.OriginalPath));
                    }
                }
            }

            AssemblyLoadResult result;

            assembly = ShadowCopyAndLoadAssembly(fullPath, out result);
            if (assembly.IsDefault)
            {
                throw new FileNotFoundException(message: null, fileName: fullPath);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private AssemblyAndLocation ShadowCopyAndLoadAndAddEntry(string originalPath, out AssemblyLoadResult result, bool explicitLoad)
        {
            AssemblyAndLocation assemblyAndLocation = Load(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);
            }

            return(assemblyAndLocation);
        }