/// <summary>
        ///   Loads all assemblies referenced on the command line
        /// </summary>
        public bool LoadReferencedAssemblies(AssemblyAdder adder)
        {
            StartTime("Loading referenced assemblies");

            int errors      = 0;
            int soft_errors = 0;

            // Load Core Library for default compilation
            if (!NoStandardLibraries)
            {
                LoadAssembly(adder, "mscorlib", ref errors, false);
            }

            foreach (string r in AssembliesToReference)
            {
                LoadAssembly(adder, r, ref errors, false);
            }

            if (!NoConfig)
            {
                foreach (string r in AssembliesToReferenceSoftly)
                {
                    if (!(AssembliesToReference.Contains(r) || AssembliesToReference.Contains(r + ".dll")))
                    {
                        LoadAssembly(adder, r, ref soft_errors, true);
                    }
                }
            }

            ShowTime("References loaded");
            return(errors == 0);
        }
Example #2
0
        private void LoadAssembly(AssemblyAdder adder, string assemblyName, ref int errors, bool soft)
        {
            Assembly a         = null;
            string   total_log = "";

            try  {
                char[] path_chars = { '/', '\\' };

                if (assemblyName.IndexOfAny(path_chars) != -1)
                {
                    a = Assembly.LoadFrom(assemblyName);
                }
                else
                {
                    string ass = assemblyName;
                    if (ass.EndsWith(".dll"))
                    {
                        ass = assemblyName.Substring(0, assemblyName.Length - 4);
                    }
                    a = Assembly.Load(ass);
                }
                adder(a);
                return;
            }
            catch (FileNotFoundException) {
                if (PathsToSearchForLibraries != null)
                {
                    foreach (string dir in PathsToSearchForLibraries)
                    {
                        string full_path = Path.Combine(dir, assemblyName + ".dll");

                        try  {
                            a = Assembly.LoadFrom(full_path);
                            adder(a);
                            return;
                        }
                        catch (FileNotFoundException ff)  {
                            total_log += ff.FusionLog;
                            continue;
                        }
                    }
                }
                if (soft)
                {
                    return;
                }

                ReportError(6, "Can not find assembly '" + assemblyName + "'\nLog: " + total_log);
            }
            catch (BadImageFormatException f)  {
                ReportError(6, "Bad file format while loading assembly\nLog: " + f.FusionLog);
            } catch (FileLoadException f) {
                ReportError(6, "File Load Exception: " + assemblyName + "\nLog: " + f.FusionLog);
            } catch (ArgumentNullException) {
                ReportError(6, "Argument Null exception");
            }

            errors++;
        }
		/// <summary>
		///   Loads all assemblies referenced on the command line
		/// </summary>
		public bool LoadReferencedAssemblies (AssemblyAdder adder)
		{
			StartTime("Loading referenced assemblies");

			int errors = 0;
			int soft_errors = 0;
			
			// Load Core Library for default compilation
			if (!NoStandardLibraries)
				LoadAssembly(adder, "mscorlib", ref errors, false);

			foreach (string r in AssembliesToReference)
				LoadAssembly(adder, r, ref errors, false);

			if (!NoConfig)
				foreach (string r in AssembliesToReferenceSoftly)
					if (!(AssembliesToReference.Contains(r) || AssembliesToReference.Contains (r + ".dll")))
						LoadAssembly(adder, r, ref soft_errors, true);
			
			ShowTime("References loaded");
			return errors == 0;
		}
		private void LoadAssembly (AssemblyAdder adder, string assemblyName, ref int errors, bool soft)
		{
			Assembly a = null;
			string total_log = "";

			try  {
				char[] path_chars = { '/', '\\' };

				if (assemblyName.IndexOfAny (path_chars) != -1)
					a = Assembly.LoadFrom(assemblyName);
				else {
					string ass = assemblyName;
					if (ass.EndsWith (".dll"))
						ass = assemblyName.Substring (0, assemblyName.Length - 4);
					a = Assembly.Load (ass);
				}
				adder(a);
				return;
			}
			catch (FileNotFoundException) {
				if (PathsToSearchForLibraries != null) {
					foreach (string dir in PathsToSearchForLibraries) {
						string full_path = Path.Combine(dir, assemblyName + ".dll");

						try  {
							a = Assembly.LoadFrom (full_path);
							adder(a);
							return;
						} 
						catch (FileNotFoundException ff)  {
							total_log += ff.FusionLog;
							continue;
						}
					}
				}
				if (soft)
					return;
					
				ReportError (6, "Can not find assembly '" + assemblyName + "'\nLog: " + total_log);
			}
			catch (BadImageFormatException f)  {
				ReportError (6, "Bad file format while loading assembly\nLog: " + f.FusionLog);
			} catch (FileLoadException f){
				ReportError (6, "File Load Exception: " + assemblyName + "\nLog: " + f.FusionLog);
			} catch (ArgumentNullException){
				ReportError (6, "Argument Null exception");
			}
						
			errors++;
		}