public bool LoadReferences(ICollection<string> references, IErrorHandler errorHandler)
        {
            bool hasLoadErrors = false;

            AssemblySet assemblySet = new AssemblySet();

            foreach (string referencePath in references) {
                string assemblyFilePath = Path.GetFullPath(referencePath);
                if (File.Exists(assemblyFilePath) == false) {
                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be located.", String.Empty);
                    hasLoadErrors = true;
                    continue;
                }

                string referenceName = Path.GetFileNameWithoutExtension(assemblyFilePath);
                if (assemblySet.IsReferenced(referenceName)) {
                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' is a duplicate reference.", String.Empty);
                    hasLoadErrors = true;

                    continue;
                }

                try {
                    AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);
                    if (assembly == null) {
                        errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be loaded as an assembly.", String.Empty);
                        hasLoadErrors = true;
                        continue;
                    }

                    if (referenceName.Equals(CoreAssemblyName, StringComparison.OrdinalIgnoreCase)) {
                        if (_coreAssemblyPath != null) {
                            errorHandler.ReportError("The core runtime assembly, mscorlib.dll must be referenced only once.", String.Empty);
                            hasLoadErrors = true;

                            continue;
                        }
                        else {
                            _coreAssemblyPath = assemblyFilePath;
                            _coreAssembly = assembly;
                        }
                    }
                    else {
                        assemblySet.AddAssembly(assemblyFilePath, referenceName, assembly);
                    }
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());

                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be loaded as an assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            if (_coreAssembly == null) {
                errorHandler.ReportError("The 'mscorlib' assembly must be referenced.", String.Empty);
                hasLoadErrors = true;
            }
            else {
                if (VerifyScriptAssembly(_coreAssembly) == false) {
                    errorHandler.ReportError("The assembly '" + _coreAssemblyPath + "' is not a valid script assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            foreach (KeyValuePair<string, AssemblyDefinition> assemblyReference in assemblySet.Assemblies) {
                if (VerifyScriptAssembly(assemblyReference.Value) == false) {
                    errorHandler.ReportError("The assembly '" + assemblyReference.Key + "' is not a valid script assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            _assemblyMap = assemblySet.Assemblies;
            _assemblyPaths = assemblySet.GetAssemblyPaths();

            return hasLoadErrors;
        }
Beispiel #2
0
        public bool LoadReferences(ICollection <string> references, IErrorHandler errorHandler)
        {
            bool hasLoadErrors = false;

            AssemblySet assemblySet = new AssemblySet();

            foreach (string referencePath in references)
            {
                string assemblyFilePath = Path.GetFullPath(referencePath);
                if (File.Exists(assemblyFilePath) == false)
                {
                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be located.", String.Empty);
                    hasLoadErrors = true;
                    continue;
                }

                string referenceName = Path.GetFileNameWithoutExtension(assemblyFilePath);
                if (assemblySet.IsReferenced(referenceName))
                {
                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' is a duplicate reference.", String.Empty);
                    hasLoadErrors = true;

                    continue;
                }

                try {
                    AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);
                    if (assembly == null)
                    {
                        errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be loaded as an assembly.", String.Empty);
                        hasLoadErrors = true;
                        continue;
                    }

                    if (referenceName.Equals(CoreAssemblyName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (_coreAssemblyPath != null)
                        {
                            errorHandler.ReportError("The core runtime assembly, mscorlib.dll must be referenced only once.", String.Empty);
                            hasLoadErrors = true;

                            continue;
                        }
                        else
                        {
                            _coreAssemblyPath = assemblyFilePath;
                            _coreAssembly     = assembly;
                        }
                    }
                    else
                    {
                        assemblySet.AddAssembly(assemblyFilePath, referenceName, assembly);
                    }
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());

                    errorHandler.ReportError("The referenced assembly '" + referencePath + "' could not be loaded as an assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            if (_coreAssembly == null)
            {
                errorHandler.ReportError("The 'mscorlib' assembly must be referenced.", String.Empty);
                hasLoadErrors = true;
            }
            else
            {
                if (VerifyScriptAssembly(_coreAssembly) == false)
                {
                    errorHandler.ReportError("The assembly '" + _coreAssemblyPath + "' is not a valid script assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            foreach (KeyValuePair <string, AssemblyDefinition> assemblyReference in assemblySet.Assemblies)
            {
                if (VerifyScriptAssembly(assemblyReference.Value) == false)
                {
                    errorHandler.ReportError("The assembly '" + assemblyReference.Key + "' is not a valid script assembly.", String.Empty);
                    hasLoadErrors = true;
                }
            }

            _assemblyMap   = assemblySet.Assemblies;
            _assemblyPaths = assemblySet.GetAssemblyPaths();

            return(hasLoadErrors);
        }
Beispiel #3
0
        public bool LoadReferences(ICollection<string> references, IErrorHandler errorHandler)
        {
            bool hasLoadErrors = false;

            AssemblySet assemblySet = new AssemblySet();

            foreach (string referencePath in references)
            {
                string assemblyFilePath = Path.GetFullPath(referencePath);

                if (File.Exists(assemblyFilePath) == false)
                {
                    errorHandler.ReportMissingAssemblyReferenceError(referencePath);
                    hasLoadErrors = true;

                    continue;
                }

                string referenceName = Path.GetFileNameWithoutExtension(assemblyFilePath);

                if (assemblySet.IsReferenced(referenceName))
                {
                    errorHandler.ReportDuplicateAssemblyReferenceError(referenceName, referencePath);
                    hasLoadErrors = true;

                    continue;
                }

                try
                {
                    AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);

                    if (assembly == null)
                    {
                        errorHandler.ReportAssemblyLoadError(referenceName, referencePath);
                        hasLoadErrors = true;

                        continue;
                    }

                    if (referenceName.Equals(CoreAssemblyName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (CoreAssemblyPath != null)
                        {
                            errorHandler.ReportDuplicateAssemblyReferenceError(referenceName, referencePath);
                            hasLoadErrors = true;
                        }
                        else
                        {
                            CoreAssemblyPath = assemblyFilePath;
                            CoreAssemblyMetadata = assembly;
                        }
                    }
                    else
                    {
                        assemblySet.AddAssembly(assemblyFilePath, referenceName, assembly);
                    }
                }
                catch (Exception e)
                {
                    Debug.Fail(e.ToString());

                    errorHandler.ReportAssemblyLoadError(referenceName, referencePath);
                    hasLoadErrors = true;
                }
            }

            if (CoreAssemblyMetadata == null)
            {
                errorHandler.ReportMissingAssemblyReferenceError(CoreAssemblyName);
                hasLoadErrors = true;
            }

            assemblyMap = assemblySet.Assemblies;
            assemblyPaths = assemblySet.GetAssemblyPaths();

            return hasLoadErrors;
        }