···11+using System;
22+using System.Reflection;
33+using System.IO;
44+55+namespace @NAMESPACE@
66+{
77+ class @MAINCLASSNAME@Wrapper
88+ {
99+ private String[] AssemblySearchPaths = { @ASSEMBLYSEARCHPATHS@ };
1010+1111+ public @MAINCLASSNAME@Wrapper()
1212+ {
1313+ AppDomain currentDomain = AppDomain.CurrentDomain;
1414+ currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
1515+ }
1616+1717+ static void Main(string[] args)
1818+ {
1919+ // Initialise the wrapper so that the missing library assemblies are loaded
2020+ new @MAINCLASSNAME@Wrapper();
2121+2222+ // Call the original main method
2323+ @MAINCLASSNAME@.Main2(args);
2424+ }
2525+2626+ private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
2727+ {
2828+ //This handler is called only when the common language runtime tries to bind to the assembly and fails.
2929+3030+ //Retrieve the list of referenced assemblies in an array of AssemblyName.
3131+ Assembly MyAssembly, executingAssemblies;
3232+ string assemblyPath = "";
3333+3434+ executingAssemblies = Assembly.GetExecutingAssembly();
3535+ AssemblyName[] referencedAssemblies = executingAssemblies.GetReferencedAssemblies();
3636+3737+ //Loop through the array of referenced assembly names.
3838+ foreach (AssemblyName assemblyName in referencedAssemblies)
3939+ {
4040+ //Check for the assembly names that have raised the "AssemblyResolve" event.
4141+ if (assemblyName.FullName.Substring(0, assemblyName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
4242+ {
4343+ //Retrieve the name of the assembly from where it has to be loaded.
4444+ String dllName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
4545+4646+ //Search for the right path of the library assembly
4747+ foreach (String currentAssemblyPath in AssemblySearchPaths)
4848+ {
4949+ assemblyPath = currentAssemblyPath + "/" + dllName;
5050+ if (File.Exists(assemblyPath))
5151+ break;
5252+ }
5353+ }
5454+ }
5555+5656+ //Load the assembly from the specified path.
5757+ MyAssembly = Assembly.LoadFrom(assemblyPath);
5858+5959+ //Return the loaded assembly.
6060+ return MyAssembly;
6161+ }
6262+6363+ }
6464+}