One of the issues with .NET applications is that they will load references Just In Time (JIT). I did this code about 2.5 years ago - but it is still useful to force the load of referenced DLLs in case your setup package doesn't deploy DLLs correctly. This code allows you to do a "sanity check" on your application if a user reports bugs when the install your Service/Windows Forms application.
1: using System;
2: using System.Collections;
3: using System.Reflection;
4: using NUnit.Framework;
5:
6: namespace UnitTest
7: {
8: /// <summary>
9: /// Forces load of all assemblies to stop any problems when the Setup Package doesn't have all the correct DLLs
10: ///(we had this specific problem when DLLs were added to SSW.Framework.WindowsUI.WizardForms FuelAdvance.Components.Windows.Wizards.dll)
11: /// (davidklein@ssw.com.au 17/06/2005)
12: /// </summary>
13: ///
14: [TestFixture()]
15: public class DLLDependencyTest
16: {
17: private static ArrayList m_LoadedDLLs;
18:
19: public DLLDependencyTest()
20: {
21: m_LoadedDLLs = new ArrayList();
22: TestLoadReferencedDLLs();
23: }
24:
25: [Test()]
26: public void TestLoadReferencedDLLs()
27: {
28: Assembly applicationToTest = AppDomain.CurrentDomain.Load("SSWeXtremeEmails");
29: LoadDLL(applicationToTest);
30: }
31:
32: private static void LoadDLL(Assembly assembly)
33: {
34: AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
35: foreach (AssemblyName referencedAssemblyName in referencedAssemblies)
36: {
37: Assembly currentReferencedAssembly = Assembly.Load(referencedAssemblyName);
38: if (!m_LoadedDLLs.Contains(currentReferencedAssembly.FullName))
39: {
40: m_LoadedDLLs.Add(currentReferencedAssembly.FullName);
41: LoadDLL(currentReferencedAssembly);
42: }
43: }
44: }
45: }
46: }
No comments:
Post a Comment