Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RuntimeAddin.cs « Mono.Addins « Mono.Addins - github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d5a03ac10b795e3d315db3b051f5600af3023d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
//
// RuntimeAddin.cs
//
// Author:
//   Lluis Sanchez Gual,
//   Georg Wächter
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Resources;
using System.Globalization;

using Mono.Addins.Description;
using Mono.Addins.Localization;
using System.Linq;
using Mono.Addins.Database;

namespace Mono.Addins
{
	/// <summary>
	/// Run-time representation of an add-in.
	/// </summary>
	public class RuntimeAddin
	{
		readonly string id;
		readonly string baseDirectory;
		readonly Addin ainfo;
		readonly RuntimeAddin parentAddin;
		readonly AddinEngine addinEngine;
		readonly ModuleDescription module;

		string privatePath;

		Dictionary<string, Assembly> loadedAssemblies = new Dictionary<string, Assembly>();
		bool fullyLoadedAssemblies;

		RuntimeAddin [] depAddins;
		ResourceManager [] resourceManagers;
		AddinLocalizer localizer;
		ExtensionNodeDescription localizerDescription;
		
		internal RuntimeAddin (AddinEngine addinEngine, Addin iad)
		{
			this.addinEngine = addinEngine;

			ainfo = iad;

			AddinDescription description = iad.Description;
			id = description.AddinId;
			baseDirectory = description.BasePath;
			module = description.MainModule;
			module.RuntimeAddin = this;
			localizerDescription = description.Localizer;
		}

		internal RuntimeAddin (AddinEngine addinEngine, RuntimeAddin parentAddin, ModuleDescription module)
		{
			this.addinEngine = addinEngine;
			this.parentAddin = parentAddin;
			this.module = module;
			id = parentAddin.id;
			baseDirectory = parentAddin.baseDirectory;
			privatePath = parentAddin.privatePath;
			ainfo = parentAddin.ainfo;
			module.RuntimeAddin = this;
		}
		
		internal ModuleDescription Module {
			get { return module; }
		}
		
		/// <summary>
		/// Identifier of the add-in.
		/// </summary>
		public string Id {
			get { return Addin.GetIdName (id); }
		}
		
		/// <summary>
		/// Version of the add-in.
		/// </summary>
		public string Version {
			get { return Addin.GetIdVersion (id); }
		}
		
		internal Addin Addin {
			get { return ainfo; }
		}

		/// <summary>
		/// Returns a string that represents the current RuntimeAddin.
		/// </summary>
		/// <returns>
		/// A string that represents the current RuntimeAddin.
		/// </returns>
		public override string ToString ()
		{
			return ainfo.ToString ();
		}

		internal bool TryGetAssembly (string assemblyName, out Assembly assembly)
		{
			return loadedAssemblies.TryGetValue (assemblyName, out assembly);
		}

		internal IEnumerable<Assembly> GetLoadedAssemblies()
		{
			return loadedAssemblies.Values;
		}

		ResourceManager[] GetResourceManagers ()
		{
			if (resourceManagers != null)
				return resourceManagers;
			
			EnsureAssembliesLoaded ();
			var managersList = new List<ResourceManager> ();

			// Search for embedded resource files
			foreach (var kvp in loadedAssemblies)
			{
				var asm = kvp.Value;
				foreach (string res in asm.GetManifestResourceNames ()) {
					if (res.EndsWith (".resources"))
						managersList.Add (new ResourceManager (res.Substring (0, res.Length - ".resources".Length), asm));
				}
			}

			return resourceManagers = managersList.ToArray ();
		}

		/// <summary>
		/// Gets a resource string
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <returns>
		/// The value of the resource string, or null if the resource can't be found.
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public string GetResourceString (string name)
		{
			return (string) GetResourceObject (name, true, null);
		}

		/// <summary>
		/// Gets a resource string
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <param name="throwIfNotFound">
		/// When set to true, an exception will be thrown if the resource is not found.
		/// </param>
		/// <returns>
		/// The value of the resource string
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public string GetResourceString (string name, bool throwIfNotFound)
		{
			return (string) GetResourceObject (name, throwIfNotFound, null);
		}

		/// <summary>
		/// Gets a resource string
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <param name="throwIfNotFound">
		/// When set to true, an exception will be thrown if the resource is not found.
		/// </param>
		/// <param name="culture">
		/// Culture of the resource
		/// </param>
		/// <returns>
		/// The value of the resource string
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public string GetResourceString (string name, bool throwIfNotFound, CultureInfo culture)
		{
			return (string) GetResourceObject (name, throwIfNotFound, culture);
		}

		/// <summary>
		/// Gets a resource object
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <returns>
		/// Value of the resource
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public object GetResourceObject (string name)
		{
			return GetResourceObject (name, true, null);
		}

		/// <summary>
		/// Gets a resource object
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <param name="throwIfNotFound">
		/// When set to true, an exception will be thrown if the resource is not found.
		/// </param>
		/// <returns>
		/// Value of the resource
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public object GetResourceObject (string name, bool throwIfNotFound)
		{
			return GetResourceObject (name, throwIfNotFound, null);
		}

		/// <summary>
		/// Gets a resource object
		/// </summary>
		/// <param name="name">
		/// Name of the resource
		/// </param>
		/// <param name="throwIfNotFound">
		/// When set to true, an exception will be thrown if the resource is not found.
		/// </param>
		/// <param name="culture">
		/// Culture of the resource
		/// </param>
		/// <returns>
		/// Value of the resource
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public object GetResourceObject (string name, bool throwIfNotFound, CultureInfo culture)
		{
			// Look in resources of this add-in
			foreach (ResourceManager manager in GetAllResourceManagers ()) {
				object t = manager.GetObject (name, culture);
				if (t != null)
					return t;
			}

			// Look in resources of dependent add-ins
			foreach (RuntimeAddin addin in GetAllDependencies ()) {
				object t = addin.GetResourceObject (name, false, culture);
				if (t != null)
					return t;
			}

			if (throwIfNotFound)
				throw new InvalidOperationException ("Resource object '" + name + "' not found in add-in '" + id + "'");

			return null;
		}

		/// <summary>
		/// Gets a type defined in the add-in
		/// </summary>
		/// <param name="typeName">
		/// Full name of the type
		/// </param>
		/// <returns>
		/// A type.
		/// </returns>
		/// <remarks>
		/// The type will be looked up in the assemblies that implement the add-in,
		/// and recursively in all add-ins on which it depends.
		/// 
		/// This method throws an InvalidOperationException if the type can't be found.
		/// </remarks>
		public Type GetType (string typeName)
		{
			return GetType (typeName, true);
		}
		
		/// <summary>
		/// Gets a type defined in the add-in
		/// </summary>
		/// <param name="typeName">
		/// Full name of the type
		/// </param>
		/// <param name="throwIfNotFound">
		/// Indicates whether the method should throw an exception if the type can't be found.
		/// </param>
		/// <returns>
		/// A <see cref="Type"/>
		/// </returns>
		/// <remarks>
		/// The type will be looked up in the assemblies that implement the add-in,
		/// and recursively in all add-ins on which it depends.
		/// 
		/// If the type can't be found, this method throw a InvalidOperationException if
		/// 'throwIfNotFound' is 'true', or 'null' otherwise.
		/// </remarks>
		public Type GetType (string typeName, bool throwIfNotFound)
		{
			// Try looking in Mono.Addins without loading the addin assemblies.
			var type = Type.GetType (typeName, false);
			if (type == null) {
				// decode the name if it's qualified
				if (Util.TryParseTypeName (typeName, out var t, out var assemblyName))
					type = GetType_Expensive (t, assemblyName ?? "");
			}
			
			if (throwIfNotFound && type == null)
				throw new InvalidOperationException ("Type '" + typeName + "' not found in add-in '" + id + "'");
			return type;
		}

		Type GetType_Expensive (string typeName, string assemblyName)
		{
			// Look in the addin assemblies and in dependent add-ins.
			// PERF: Unrolled from GetAllAssemblies and GetAllDependencies to avoid allocations.
			EnsureAssembliesLoaded ();

			foreach (var kvp in loadedAssemblies) {
				var assembly = kvp.Value;
				if (string.IsNullOrEmpty (assemblyName) || assembly.FullName == assemblyName) {
					Type type = assembly.GetType (typeName, false);
					if (type != null)
						return type;
				}
			}

			var addins = GetDepAddins ();
			if (addins != null) {
				foreach (RuntimeAddin addin in addins) {
					Type t = addin.GetType_Expensive (typeName, assemblyName);
					if (t != null)
						return t;
				}
			}

			return parentAddin?.GetType_Expensive (typeName, assemblyName);
		}

		IEnumerable<ResourceManager> GetAllResourceManagers ()
		{
			foreach (ResourceManager rm in GetResourceManagers ())
				yield return rm;
			
			if (parentAddin != null) {
				foreach (ResourceManager rm in parentAddin.GetResourceManagers ())
					yield return rm;
			}
		}
		
		IEnumerable<Assembly> GetAllAssemblies ()
		{
			foreach (Assembly asm in loadedAssemblies.Values)
				yield return asm;
			
			// Look in the parent addin assemblies
			
			if (parentAddin != null) {
				foreach (Assembly asm in parentAddin.loadedAssemblies.Values)
					yield return asm;
			}
		}
		
		IEnumerable<RuntimeAddin> GetAllDependencies ()
		{
			// Look in the dependent add-ins
			foreach (RuntimeAddin addin in GetDepAddins ())
				yield return addin;
			
			if (parentAddin != null) {
				// Look in the parent dependent add-ins
				foreach (RuntimeAddin addin in parentAddin.GetDepAddins ())
					yield return addin;
			}
		}
		
		/// <summary>
		/// Creates an instance of a type defined in the add-in
		/// </summary>
		/// <param name="typeName">
		/// Name of the type.
		/// </param>
		/// <returns>
		/// A new instance of the type
		/// </returns>
		/// <remarks>
		/// The type will be looked up in the assemblies that implement the add-in,
		/// and recursively in all add-ins on which it depends.
		/// 
		/// This method throws an InvalidOperationException if the type can't be found.
		/// 
		/// The specified type must have a default constructor.
		/// </remarks>
		public object CreateInstance (string typeName)
		{
			return CreateInstance (typeName, true);
		}
		
		/// <summary>
		/// Creates an instance of a type defined in the add-in
		/// </summary>
		/// <param name="typeName">
		/// Name of the type.
		/// </param>
		/// <param name="throwIfNotFound">
		/// Indicates whether the method should throw an exception if the type can't be found.
		/// </param>
		/// <returns>
		/// A new instance of the type
		/// </returns>
		/// <remarks>
		/// The type will be looked up in the assemblies that implement the add-in,
		/// and recursively in all add-ins on which it depends.
		/// 
		/// If the type can't be found, this method throw a InvalidOperationException if
		/// 'throwIfNotFound' is 'true', or 'null' otherwise.
		/// 
		/// The specified type must have a default constructor.
		/// </remarks>
		public object CreateInstance (string typeName, bool throwIfNotFound)
		{
			Type type = GetType(typeName, throwIfNotFound);
			if (type == null)
				return null;
			else
				return Activator.CreateInstance(type, true);
		}
		
		/// <summary>
		/// Gets the path of an add-in file
		/// </summary>
		/// <param name="fileName">
		/// Relative path of the file
		/// </param>
		/// <returns>
		/// Full path of the file
		/// </returns>
		/// <remarks>
		/// This method can be used to get the full path of a data file deployed together with the add-in.
		/// </remarks>
		public string GetFilePath (string fileName)
		{
			return Path.Combine (baseDirectory, fileName);
		}

		/// <summary>
		/// Gets the path of an add-in file
		/// </summary>
		/// <param name="filePath">
		/// Components of the file path
		/// </param>
		/// <returns>
		/// Full path of the file
		/// </returns>
		/// <remarks>
		/// This method can be used to get the full path of a data file deployed together with the add-in.
		/// </remarks>
		public string GetFilePath (params string[] filePath)
		{
			return Path.Combine (baseDirectory, string.Join ("" + Path.DirectorySeparatorChar, filePath));
		}
		
		/// <summary>
		/// Path to a directory where add-ins can store private configuration or status data
		/// </summary>
		public string PrivateDataPath {
			get {
				if (privatePath == null) {
					privatePath = ainfo.PrivateDataPath;
					if (!Directory.Exists (privatePath))
						Directory.CreateDirectory (privatePath);
				}
				return privatePath;
			}
		}
		
		/// <summary>
		/// Gets the content of a resource
		/// </summary>
		/// <param name="resourceName">
		/// Name of the resource
		/// </param>
		/// <returns>
		/// Content of the resource, or null if not found
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public Stream GetResource (string resourceName)
		{
			return GetResource (resourceName, false);
		}
		
		/// <summary>
		/// Gets the content of a resource
		/// </summary>
		/// <param name="resourceName">
		/// Name of the resource
		/// </param>
		/// <param name="throwIfNotFound">
		/// When set to true, an exception will be thrown if the resource is not found.
		/// </param>
		/// <returns>
		/// Content of the resource.
		/// </returns>
		/// <remarks>
		/// The add-in engine will look for resources in the main add-in assembly and in all included add-in assemblies.
		/// </remarks>
		public Stream GetResource (string resourceName, bool throwIfNotFound)
		{
			EnsureAssembliesLoaded ();
			
			// Look in the addin assemblies
			
			foreach (Assembly asm in GetAllAssemblies ()) {
				Stream res = asm.GetManifestResourceStream (resourceName);
				if (res != null)
					return res;
			}
			
			// Look in the dependent add-ins
			foreach (RuntimeAddin addin in GetAllDependencies ()) {
				Stream res = addin.GetResource (resourceName);
				if (res != null)
					return res;
			}
			
			if (throwIfNotFound)
				throw new InvalidOperationException ("Resource '" + resourceName + "' not found in add-in '" + id + "'");
				
			return null;
		}
		
		/// <summary>
		/// Returns information about how the given resource has been persisted
		/// </summary>
		/// <param name="resourceName">
		/// Name of the resource
		/// </param>
		/// <returns>
		/// Resource information, or null if the resource doesn't exist
		/// </returns>
		public ManifestResourceInfo GetResourceInfo (string resourceName)
		{
			EnsureAssembliesLoaded ();

			// Look in the addin assemblies

			foreach (Assembly asm in GetAllAssemblies ()) {
				var res = asm.GetManifestResourceInfo (resourceName);
				if (res != null) {
					// Mono doesn't set the referenced assembly
					if (res.ReferencedAssembly == null)
						return new ManifestResourceInfo (asm, res.FileName, res.ResourceLocation);
					return res;
				}
			}

			// Look in the dependent add-ins
			foreach (RuntimeAddin addin in GetAllDependencies ()) {
				var res = addin.GetResourceInfo (resourceName);
				if (res != null)
					return res;
			}

			return null;
		}

		/// <summary>
		/// Localizer which can be used to localize strings defined in this add-in
		/// </summary>
		public AddinLocalizer Localizer {
			get {
				// If this is an optional module, the localizer is defined in the parent
				if (parentAddin != null)
					return parentAddin.Localizer;
				else
					return LoadLocalizer () ?? addinEngine.DefaultLocalizer;
			}
		}
		
		internal RuntimeAddin GetModule (ModuleDescription module)
		{
			// If requesting the root module, return this
			if (module == module.ParentAddinDescription.MainModule)
				return this;
			
			if (module.RuntimeAddin != null)
				return module.RuntimeAddin;
			
			RuntimeAddin addin = new RuntimeAddin (addinEngine, this, module);
			return addin;
		}
		
		AddinLocalizer LoadLocalizer ()
		{
			if (localizerDescription != null) {
				string cls = localizerDescription.GetAttribute ("type");

				// First try getting one of the stock localizers. If none of found try getting the type.
				// They are not encoded as an assembly qualified name
				object fob = null;
				if (cls.IndexOf (',') == -1) {
					Type t = GetType ().Assembly.GetType ("Mono.Addins.Localization." + cls + "Localizer", false);
					if (t != null)
						fob = Activator.CreateInstance (t);
				}

				if (fob == null)
					fob = CreateInstance (cls, true);

				IAddinLocalizerFactory factory = fob as IAddinLocalizerFactory;
				if (factory == null)
					throw new InvalidOperationException ("Localizer factory type '" + cls + "' must implement IAddinLocalizerFactory");
				localizer = new AddinLocalizer (factory.CreateLocalizer (this, localizerDescription));
				localizerDescription = null;
			}
			return localizer;
		}

		RuntimeAddin [] GetDepAddins ()
		{
			if (depAddins != null)
				return depAddins;
			
			var plugList = new List<RuntimeAddin> ();
			string ns = ainfo.Description.Namespace;
			
			// Collect dependent ids
			foreach (Dependency dep in module.Dependencies) {
				AddinDependency pdep = dep as AddinDependency;
				if (pdep != null) {
					RuntimeAddin adn = addinEngine.GetAddin (Addin.GetFullId (ns, pdep.AddinId, pdep.Version));
					if (adn != null)
						plugList.Add (adn);
					else
						addinEngine.ReportError ("Add-in dependency not loaded: " + pdep.FullAddinId, module.ParentAddinDescription.AddinId, null, false);
				}
			}
			return depAddins = plugList.ToArray ();
		}

		internal void RegisterAssemblyLoad(string assemblyName, Assembly assembly)
		{
			loadedAssemblies.Add (assemblyName, assembly);
		}
		
		void LoadModule (ModuleDescription module)
		{
			// Load the assemblies
			for (int i = 0; i < module.Assemblies.Count; ++i) {
				if (loadedAssemblies.TryGetValue(module.AssemblyNames[i], out var asm))
					continue;

				// Backwards compat: Load all the addins on demand if an assembly name
				// is not supplied for the type.

				// don't load the assembly if it's already loaded
				string asmPath = GetFilePath (module.Assemblies[i]);
				foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
					// Sorry, you can't load addins from
					// dynamic assemblies as get_Location
					// throws a NotSupportedException
                    if (a is System.Reflection.Emit.AssemblyBuilder || a.IsDynamic) {
						continue;
					}
					
					try {
						if (a.Location == asmPath) {
							asm = a;
							break;
						}
					} catch (NotSupportedException) {
						// Some assemblies don't have a location
					}
				}

				if (asm == null) {
					asm = Assembly.LoadFrom (asmPath);
				}

				RegisterAssemblyLoad(module.AssemblyNames[i], asm);
			}
		}
		
		internal void UnloadExtensions (ExtensionContextTransaction transaction)
		{
			addinEngine.UnregisterAddinNodeSets (transaction, id);
		}
		
		bool CheckAddinDependencies (ModuleDescription module, bool forceLoadAssemblies)
		{
			foreach (Dependency dep in module.Dependencies) {
				AddinDependency pdep = dep as AddinDependency;
				if (pdep == null)
					continue;
				if (!addinEngine.IsAddinLoaded (pdep.FullAddinId))
					return false;
				if (forceLoadAssemblies)
					addinEngine.GetAddin (pdep.FullAddinId).EnsureAssembliesLoaded ();
			}
			return true;
		}
		
		internal void EnsureAssembliesLoaded ()
		{
			if (fullyLoadedAssemblies)
				return;
			fullyLoadedAssemblies = true;

			// Load the assemblies of the module
			CheckAddinDependencies (module, true);
			LoadModule (module);
			addinEngine.ReportAddinAssembliesLoad (id);
		}
	}
}