Esempio n. 1
0
        private Assembly SbmqmDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string asmName        = args.Name.Split(',')[0];
            bool   hasFullAsmName = args.Name.Contains(',');

            // Resolve from Adapters
            var root = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            var fn   = Path.Combine(root, asmName + ".dll");

            if (File.Exists(fn))
            {
                return(Assembly.LoadFrom(fn));
            }
            else
            {
                var mgrFilePath = ServiceBusFactory.GetManagerFilePath(Config.ServiceBus, Config.ServiceBusVersion, Config.ServiceBusQueueType);
                if (mgrFilePath.IsValid())
                {
                    string adapterPath = Path.GetDirectoryName(mgrFilePath);

                    fn = Path.Combine(adapterPath, asmName + ".dll");
                    if (File.Exists(fn) && (!hasFullAsmName || AssemblyName.GetAssemblyName(fn).FullName == args.Name))
                    {
                        return(Assembly.LoadFrom(fn));
                    }
                }

                string adaptersPath = root + "\\Adapters\\";
                foreach (var dir in Directory.GetDirectories(adaptersPath))
                {
                    fn = Path.Combine(dir, asmName + ".dll");
                    if (File.Exists(fn) && (!hasFullAsmName || AssemblyName.GetAssemblyName(fn).FullName == args.Name))
                    {
                        return(Assembly.LoadFrom(fn));
                    }
                }
            }


            // Resolve from Assembly Paths
            if (Config != null)
            {
                foreach (var path in Config.CurrentServer.CommandsAssemblyPaths)
                {
                    var fileName = string.Format("{0}\\{1}.dll", path, asmName);

                    try {
                        if (File.Exists(fileName)) // && AssemblyName.GetAssemblyName(fileName).FullName == args.Name ) {
                        {
                            return(Assembly.LoadFrom(fileName));
                        }
                    } catch { }
                }
            }



            if (!args.Name.StartsWith("mscorlib.XmlSerializers"))
            {
                throw new ApplicationException("Failed resolving assembly, " + args.Name);
            }

            return(null);
        }