System.Windows.Deployment.LoadAssemblies C# (CSharp) Method

LoadAssemblies() private method

private LoadAssemblies ( ) : bool
return bool
		internal bool LoadAssemblies ()
		{
			assemblies = new List <Assembly> ();
			assemblies.Add (typeof (Application).Assembly);
			
			pending_assemblies = Parts != null ? Parts.Count : 0;

			for (int i = 0; i < ExternalParts.Count; i++) {
				ExtensionPart ext = ExternalParts[i] as ExtensionPart;

				if (ext != null) {
					try {
						// TODO These ExternalPart assemblies should really be placed in
						// a global long term cache but simply make sure we load them for now
						Console.WriteLine ("Attempting To Load ExternalPart {0}", ext.Source);

						DownloadAssembly (ext.Source, 2152);

						pending_assemblies++;
					} catch (Exception e) {
						int error = (e is MethodAccessException) ? 4004 : 2152;
						throw new MoonException (error, string.Format ("Error while loading the '{0}' ExternalPart: {1}", ext.Source, e.Message));
					}
				}
			}

			for (int i = 0; Parts != null && i < Parts.Count; i++) {
				var source = Parts [i].Source;

				try {
					bool try_downloading = false;
					string canon = Helper.CanonicalizeAssemblyPath (source);
					string filename = Path.GetFullPath (Path.Combine (XapDir, canon));
					// note: the content of the AssemblyManifest.xaml file is untrusted
					if (filename.StartsWith (XapDir)) {
						try {
							Assembly asm = Assembly.LoadFrom (filename);
							AssemblyRegister (asm);
							if (pending_assemblies == 0)
								return true;
						} catch (FileNotFoundException) {
							try_downloading = true;
						}
					} else {
						// we can hit a Part with a relative URI starting with a '/' which fails the above test
						try_downloading = true;
					}

					if (!try_downloading)
						continue;

					DownloadAssembly (new Uri (source, UriKind.RelativeOrAbsolute), 2105);
				} catch (Exception e) {
					int error = (e is MethodAccessException) ? 4004 : 2105;
					throw new MoonException (error, string.Format ("Error while loading the '{0}' assembly : {1}", source, e.Message));
				}
			}

			// unmanaged (JS/XAML only) applications can go directly to create the application
			return pending_assemblies == 0 ? CreateApplication () : true;
		}