···1+using System;
2+using System.Reflection;
3+using System.IO;
4+5+namespace @NAMESPACE@
6+{
7+ class @MAINCLASSNAME@Wrapper
8+ {
9+ private String[] AssemblySearchPaths = { @ASSEMBLYSEARCHPATHS@ };
10+11+ public @MAINCLASSNAME@Wrapper()
12+ {
13+ AppDomain currentDomain = AppDomain.CurrentDomain;
14+ currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
15+ }
16+17+ static void Main(string[] args)
18+ {
19+ // Initialise the wrapper so that the missing library assemblies are loaded
20+ new @MAINCLASSNAME@Wrapper();
21+22+ // Call the original main method
23+ @MAINCLASSNAME@.Main2(args);
24+ }
25+26+ private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
27+ {
28+ //This handler is called only when the common language runtime tries to bind to the assembly and fails.
29+30+ //Retrieve the list of referenced assemblies in an array of AssemblyName.
31+ Assembly MyAssembly, executingAssemblies;
32+ string assemblyPath = "";
33+34+ executingAssemblies = Assembly.GetExecutingAssembly();
35+ AssemblyName[] referencedAssemblies = executingAssemblies.GetReferencedAssemblies();
36+37+ //Loop through the array of referenced assembly names.
38+ foreach (AssemblyName assemblyName in referencedAssemblies)
39+ {
40+ //Check for the assembly names that have raised the "AssemblyResolve" event.
41+ if (assemblyName.FullName.Substring(0, assemblyName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
42+ {
43+ //Retrieve the name of the assembly from where it has to be loaded.
44+ String dllName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
45+46+ //Search for the right path of the library assembly
47+ foreach (String currentAssemblyPath in AssemblySearchPaths)
48+ {
49+ assemblyPath = currentAssemblyPath + "/" + dllName;
50+ if (File.Exists(assemblyPath))
51+ break;
52+ }
53+ }
54+ }
55+56+ //Load the assembly from the specified path.
57+ MyAssembly = Assembly.LoadFrom(assemblyPath);
58+59+ //Return the loaded assembly.
60+ return MyAssembly;
61+ }
62+63+ }
64+}