/// <summary> Ensures that the internal dictionary is populated with the set of initially loaded assemblies. </summary> /// <remarks> Under Silverlight, this call must be made on the main thread. </remarks> public static void EnsureAssemblyByName() { if (_assemblyByName == null) { if ( System.Threading.Interlocked.CompareExchange <Dictionary <string, Assembly> > ( ref _assemblyByName, new Dictionary <string, Assembly>(), null ) == null ) { lock (_assemblyByName) { #if SILVERLIGHT foreach (var part in System.Windows.Deployment.Current.Parts) { RegisterAssembly ( new System.Windows.AssemblyPart().Load ( System.Windows.Application.GetResourceStream ( new Uri(part.Source, UriKind.Relative) ).Stream ) ); } #else foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!_assemblyByName.ContainsKey(AssemblyNameUtility.GetName(assembly.FullName))) { RegisterAssembly(assembly); } } #endif } } } }
/// <summary> Registers an assembly for resolution by weak (short) name. </summary> public static void RegisterAssembly(Assembly assembly) { EnsureAssemblyByName(); lock (_assemblyByName) _assemblyByName[AssemblyNameUtility.GetName(assembly.FullName)] = assembly; }