コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
 private AssemblyAndLocation ShadowCopyAndLoadAssembly(string originalPath, out AssemblyLoadResult result)
 {
     return(ShadowCopyAndLoadAndAddEntry(originalPath, out result, explicitLoad: true));
 }
コード例 #4
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;
        }
コード例 #5
0
 private AssemblyAndLocation ShadowCopyAndLoadAssembly(string originalPath, out AssemblyLoadResult result)
 {
     return ShadowCopyAndLoadAndAddEntry(originalPath, out result, explicitLoad: true);
 }
コード例 #6
0
 private SerializableAssemblyLoadResult(AssemblyLoadResult result)
 {
     Path = result.Path;
     OriginalPath = result.OriginalPath;
     IsSuccessful = result.IsSuccessful;
 }