상속: EventArgs
예제 #1
0
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     Assembly asm;
     if (!AssemblyCache.TryGetValue(args.Name, out asm))
     {
         var name = args.Name;
         var index = name.IndexOf(",");
         if (index > 0)
             name = name.Substring(0, index);
         foreach (var path in BinPath)
         {
             var filename = name + ".dll";
             var filepath = Path.Combine(path, filename);
             if (!File.Exists(filepath))
             {
                 filepath = Path.ChangeExtension(filepath, ".exe");
             }
             if (File.Exists(filepath))
             {
                 asm = Assembly.LoadFrom(filepath);
                 if (asm != null)
                 {
                     AssemblyCache[asm.FullName] = asm;
                     Console.WriteLine("Assembly resolver found assembly "+asm.Location);
                     break;
                 }
             }
         }
     }
     return asm;
 }
예제 #2
0
        private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            var name = args.Name.Split(',')[0];

            if (name.Equals("Microsoft.UpdateServices.Administration"))
            {
                // Microsoft changed version numbers when putting WSUS Admin API into RSAT.
                // Need to try and maintain backward compatability.

                if (!alreadyTriedRedirect)
                {
                    alreadyTriedRedirect = true;

                    var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                    if (!programFiles.EndsWith(@"\"))
                    {
                        programFiles = programFiles + @"\";
                    }

                    redirect = Assembly.LoadFrom(string.Format("{0}Update Services\\Api\\Microsoft.UpdateServices.Administration.dll", programFiles));
                }

                return redirect;
            }

            return null;
        }
예제 #3
0
파일: Program.cs 프로젝트: kazyx/SvgToXaml
        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
        {
            Assembly cachedAsm;
            if (loadedAsmsCache.TryGetValue(args.Name, out cachedAsm))
                return cachedAsm;

            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            AssemblyName assemblyName = new AssemblyName(args.Name);

            string path = assemblyName.Name + ".dll";
            if (assemblyName.CultureInfo != null && assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
            {
                path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
            }

            using (Stream stream = executingAssembly.GetManifestResourceStream(path))
            {
                if (stream == null)
                    return null;

                byte[] assemblyRawBytes = new byte[stream.Length];
                stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
                var loadedAsm = Assembly.Load(assemblyRawBytes);
                loadedAsmsCache.Add(args.Name, loadedAsm);
                return loadedAsm;
            }
        }
        public Assembly OnAssemblyResolve(object sender,
            ResolveEventArgs args)
        {
            if (!(sender is AppDomain))
                return null;

            string[] pathList = new[]
                                    {
                                        Path.Combine(Directory.GetCurrentDirectory(), "bin"),
                                        Path.Combine(Directory.GetCurrentDirectory(), PathToSearch),
                                        Path.Combine(Directory.GetCurrentDirectory(),
                                                     Path.Combine(PathToSearch, "Scripts")),
                                        Directory.GetCurrentDirectory(),
                                    };

            string assemblyName = args.Name;
            if (assemblyName.IndexOf(",") != -1)
                assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));

            foreach (string s in pathList)
            {
                string path = Path.Combine(s, assemblyName) + ".dll";

                if (File.Exists(path))
                    return Assembly.Load(AssemblyName.GetAssemblyName(path));
            }
            return null;
        }
예제 #5
0
        private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            lock (syncRoot)
            {
                if (checkedAssemblies.Add(args.Name))
                {
                    var assemblyName = new AssemblyName(args.Name);
                    if (!assemblyName.Name.EndsWith(".resources"))
                    {
                        var stream = typeof(AssemblyResolver).Assembly.GetManifestResourceStream(typeof(AssemblyResolver), assemblyName.Name + ".pkg");
                        if (stream != null)
                        {
                            using (var package = Package.Open(stream))
                            {
                                var partUri = PackUriHelper.CreatePartUri(new Uri(assemblyName.Name + ".dll", UriKind.Relative));
                                if (package.PartExists(partUri))
                                {
                                    var part = package.GetPart(partUri);
                                    var ms = new MemoryStream();
                                    part.GetStream().CopyTo(ms);
                                    return Assembly.Load(ms.ToArray());
                                }
                            }
                        }
                    }
                }

                return null;
            }
        }
예제 #6
0
        private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            var requestedName = new AssemblyName(args.Name);

            if (knownAssemblies.ContainsKey(requestedName.Name))
            {
                foreach (var item in knownAssemblies[requestedName.Name])
                {
                    if (requestedName.Name == item.Item1.Name &&
                            (requestedName.Version == null || requestedName.Version == item.Item1.Version) &&
                            (requestedName.CultureInfo == null || requestedName.CultureInfo == item.Item1.CultureInfo) &&
                            (requestedName.GetPublicKey() == null || requestedName.GetPublicKey() == item.Item1.GetPublicKey()))
                    {
                        var path = Path.Combine(item.Item2, requestedName.Name + ".dll");
                        if (File.Exists(path))
                            return Assembly.LoadFrom(path);
                    }
                }
            }

            foreach (var directory in searchDirectories)
            {
                var path = Path.Combine(directory, requestedName.Name + ".dll");
                if (File.Exists(path))
                    return Assembly.LoadFrom(path);
            }

            return null;
        }
		Assembly AssemblyResolve(object sender, ResolveEventArgs e)
		{
			AssemblyName name = new AssemblyName(e.Name);
			LoggingService.Debug("ProjectContentRegistry.AssemblyResolve " + e.Name);
			string path = Path.Combine(lookupDirectory, name.Name);
			if (File.Exists(path + ".dll")) {
				return Assembly.ReflectionOnlyLoadFrom(path + ".dll");
			}
			if (File.Exists(path + ".exe")) {
				return Assembly.ReflectionOnlyLoadFrom(path + ".exe");
			}
			if (File.Exists(path)) {
				return Assembly.ReflectionOnlyLoadFrom(path);
			}
			try {
				LoggingService.Debug("AssemblyResolve trying ReflectionOnlyLoad");
				return Assembly.ReflectionOnlyLoad(e.Name);
			} catch (FileNotFoundException) {
				LoggingService.Warn("AssemblyResolve: ReflectionOnlyLoad failed for " + e.Name);
				// We can't get the assembly we want.
				// But propably we can get a similar version of it.
				DomAssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name);
				LoggingService.Info("AssemblyResolve: FixedName: " + fixedName);
				return Assembly.ReflectionOnlyLoad(fixedName.FullName);
			}
		}
예제 #8
0
		Assembly AssemblyResolve(object sender, ResolveEventArgs args) {
			var assembly = Get(args.Name);
			if (assembly != null)
				return assembly;

			var asmName = new AssemblyName(args.Name);
			foreach (var path in assemblySearchPaths) {
				foreach (var ext in assemblyExtensions) {
					try {
						var filename = Path.Combine(path, asmName.Name + ext);
						if (!new FileInfo(filename).Exists)
							continue;
						AddConfigFile(filename + ".config");
						return AddAssembly(Assembly.LoadFile(filename));
					}
					catch (IOException) {
					}
					catch (BadImageFormatException) {
					}
					catch (ArgumentException) {
					}
					catch (NotSupportedException) {
					}
					catch (UnauthorizedAccessException) {
					}
					catch (System.Security.SecurityException) {
					}
				}
			}

			return null;
		}
예제 #9
0
        static Assembly OnAppDomainAssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (assemblyResolveReentrant)
            {
                return null;
            }

            assemblyResolveReentrant = true;
            try
            {
                try
                {
                    return Assembly.Load(args.Name);
                }
                catch (FileNotFoundException)
                {
                    return null;
                }
                catch (FileLoadException)
                {
                    return null;
                }
                catch (BadImageFormatException)
                {
                    return null;
                }
            }
            finally
            {
                assemblyResolveReentrant = false;
            }
        }
예제 #10
0
        public static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
        {
            string assemblyName = new AssemblyName(args.Name).Name + ".dll";
            if(assemblyName.Contains(".resources"))
            {
                //Console.WriteLine("AssemblyResolve: {0}", assemblyName);
                return null;
            }

            string fullAssemblyName = string.Empty;
            foreach(var manifestResource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if(manifestResource.Contains(assemblyName))
                {
                    fullAssemblyName = manifestResource;
                    break;
                }
            }

            if(fullAssemblyName == string.Empty)
                return null;

            using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullAssemblyName))
            {
                byte[] assemblyData = new byte[stream.Length];
                stream.Read(assemblyData, 0, assemblyData.Length);
                return Assembly.Load(assemblyData);
            }
        }
예제 #11
0
        // This method loads Assemblys such as the SharpZipLib which is needed for bz2-files.
        // But only when they're needed. That makes it so special...
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (!args.Name.Contains("ICSharpCode.SharpZipLib"))
            {
                return null;
            }

            Assembly result = null;
            using (Stream embedded = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(Program).Namespace + ".ICSharpCode.SharpZipLib.dll"))
            {
                byte[] buffer = new byte[embedded.Length];
                int length = buffer.Length;
                int offset = 0;
                while (length > 0)
                {
                    int read = embedded.Read(buffer, offset, length);
                    if (read == 0)
                    {
                        break;
                    }
                    length -= read;
                    offset += read;
                }
                result = Assembly.Load(buffer);
            }

            return result;
        }
예제 #12
0
        private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            try {
                // This handler is called only when the common language runtime tries to bind to the assembly and fails.
                // Retrieve the assembly in addin directoriess
                int index = args.Name.IndexOf(",");
                string assemblyName = index >= 0 ? args.Name.Substring(0, index) : args.Name;
                Assembly assembly = null;
                string path = null;
                
                for (int i = 0; i < addinDirectories.Count; i++) {
                    string dir = addinDirectories[i];
                    string tempPath = Path.Combine(dir, assemblyName + ".dll");
                    
                    if(File.Exists(tempPath))
                    {
                        path = tempPath;
                        break;
                    }
                }
                
                if(path != null)
                    assembly = System.Reflection.Assembly.LoadFrom(path);

                return assembly;
            }
            catch(Exception ex)
            {
                MessageService.ShowError("The assembly '" + args.Name + "' could not be loaded:\n" + ex.ToString());
            }
            
            return null;
        }
		static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
		{
			string assemblyPath = Path.Combine(_path, new AssemblyName(args.Name).Name + ".dll");
			if (File.Exists(assemblyPath) == false) return null;
			Assembly assembly = Assembly.LoadFrom(assemblyPath);
			return assembly;
		}
예제 #14
0
        /// <summary>
        /// Handler to the ApplicationDomain's AssemblyResolve event.
        /// If an assembly's location cannot be resolved, an exception is
        /// thrown. Failure to resolve an assembly will leave Dynamo in 
        /// a bad state, so we should throw an exception here which gets caught 
        /// by our unhandled exception handler and presents the crash dialogue.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            try
            {
                // First check the core path
                string assemblyPath = Path.Combine(DynamoPathManager.Instance.MainExecPath, new AssemblyName(args.Name).Name + ".dll");
                if (File.Exists(assemblyPath))
                {
                    return Assembly.LoadFrom(assemblyPath);
                }

                // Then check all additional resolution paths
                foreach (var addPath in DynamoPathManager.Instance.AdditionalResolutionPaths)
                {
                    assemblyPath = Path.Combine(addPath, new AssemblyName(args.Name).Name + ".dll");
                    if (File.Exists(assemblyPath))
                    {
                        return Assembly.LoadFrom(assemblyPath);
                    }
                }

                return null;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("There location of the assembly, {0} could not be resolved for loading.", args.Name), ex);
            }
        }
예제 #15
0
        static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
        {
            //This handler is called only when the common language runtime tries to bind to the assembly and fails.

            //Load required DLL form a embeded Ressources
            Assembly a1 = Assembly.GetExecutingAssembly(); // Get Executing Assembly

            //Find the Name of the missing Dll to Load
            string Name = a1.GetName().Name + ".DLL." + args.Name.Split(',')[0];

            //Get a List of Embeded Ressources
            string[] str = a1.GetManifestResourceNames();
            byte[] block = null;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i].StartsWith(Name))//Does not check for the Extension, SO multiple extension are a not OK. Or if the File Name does not match the Namespace
                {
                    Stream s = a1.GetManifestResourceStream(str[i]);
                    block = new byte[s.Length];
                    s.Read(block, 0, block.Length);
                    break;
                }
            }

            Assembly a2 = Assembly.Load(block);
            return a2;
        }
예제 #16
0
        public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            var name = new AssemblyName(args.Name).Name.ToLowerInvariant();
            var existingAssembly = ReadExistingAssembly(name);
            if (existingAssembly != null)
            {
                return existingAssembly;
            }

            var prefix = string.Concat("costura.", name);
            var executingAssembly = Assembly.GetExecutingAssembly();

            byte[] assemblyData;
            using (var assemblyStream = GetAssemblyStream(executingAssembly, prefix))
            {
                if (assemblyStream == null)
                {
                    return null;
                }
                assemblyData = ReadStream(assemblyStream);
            }

            using (var pdbStream = GetDebugStream(executingAssembly, prefix))
            {
                if (pdbStream != null)
                {
                    var pdbData = ReadStream(pdbStream);
                    return Assembly.Load(assemblyData, pdbData);
                }
            }

            return Assembly.Load(assemblyData);
        }
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     if (args.Name.StartsWith("System.Data.SQLite")) {
         return sqliteAssembly;
     }
     return null;
 }
예제 #18
0
		static Assembly Resolve(object sender, ResolveEventArgs e) {
			byte[] b = Encoding.UTF8.GetBytes(new AssemblyName(e.Name).FullName.ToUpperInvariant());

			Stream m = null;
			if (b.Length + 4 <= key.Length) {
				for (int i = 0; i < b.Length; i++)
					b[i] *= key[i + 4];
				string n = Convert.ToBase64String(b);
				m = Assembly.GetEntryAssembly().GetManifestResourceStream(n);
			}
			if (m != null) {
				var d = new uint[m.Length >> 2];
				var t = new byte[0x100];
				int r;
				int o = 0;
				while ((r = m.Read(t, 0, 0x100)) > 0) {
					Buffer.BlockCopy(t, 0, d, o, r);
					o += r;
				}
				uint s = 0x6fff61;
				foreach (byte c in b)
					s = s * 0x5e3f1f + c;
				GCHandle h = Decrypt(d, s);

				var f = (byte[])h.Target;
				Assembly a = Assembly.Load(f);
				Array.Clear(f, 0, f.Length);
				h.Free();
				Array.Clear(d, 0, d.Length);

				return a;
			}
			return null;
		}
예제 #19
0
		public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
		{
			if (e.Name != "System.Web_test")
				return null;

			return Assembly.GetExecutingAssembly ();
		}
예제 #20
0
 void eCX()
 {
     System.Web.Security.MembershipPasswordException qTY = new System.Web.Security.MembershipPasswordException();
     System.Exception tOOK = new System.Exception();
     System.Threading.SynchronizationContext            MaH     = new System.Threading.SynchronizationContext();
     System.Web.UI.WebControls.WebParts.PageCatalogPart ayRmRe  = new System.Web.UI.WebControls.WebParts.PageCatalogPart();
     System.Web.Security.DefaultAuthenticationModule    Exmkenb = new System.Web.Security.DefaultAuthenticationModule();
     System.Web.SessionState.SessionStateModule         TmbqbT  = new System.Web.SessionState.SessionStateModule();
     System.ResolveEventArgs cGQ = new System.ResolveEventArgs("oYfQTFJiOZSVw");
     System.Web.UI.ControlValuePropertyAttribute LIX = new System.Web.UI.ControlValuePropertyAttribute("zCbHRvFJUat", 910602186);
     System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute rfLFm = new System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute();
     System.Net.HttpListenerException                         tIez            = new System.Net.HttpListenerException(2135436060, "NJgG");
     System.WeakReference                                     mKrXQJ          = new System.WeakReference(1723804374);
     System.Web.Configuration.OutputCacheProfile              atJh            = new System.Web.Configuration.OutputCacheProfile("ArZxwFnPdDdni");
     System.ParamArrayAttribute                               TyUXndy         = new System.ParamArrayAttribute();
     System.Runtime.Serialization.OnDeserializingAttribute    lVgFArZ         = new System.Runtime.Serialization.OnDeserializingAttribute();
     System.Data.SqlTypes.TypeNumericSchemaImporterExtension  QbBDir          = new System.Data.SqlTypes.TypeNumericSchemaImporterExtension();
     System.Windows.Forms.ListViewGroup                       MvRc            = new System.Windows.Forms.ListViewGroup("ELItUnvMGVWDmEGD");
     System.ComponentModel.Design.CheckoutException           NwMcuF          = new System.ComponentModel.Design.CheckoutException("QdlJvFMgCKYGHpcTb");
     System.Globalization.RegionInfo                          tAChNgq         = new System.Globalization.RegionInfo(2015922813);
     System.Web.UI.WebControls.ValidationSummary              kcldBEv         = new System.Web.UI.WebControls.ValidationSummary();
     System.Windows.Forms.RelatedImageListAttribute           PFSRAV          = new System.Windows.Forms.RelatedImageListAttribute("ZtfKTawcAmWr");
     System.Web.UI.WebControls.TableSectionStyle              ehekxI          = new System.Web.UI.WebControls.TableSectionStyle();
     System.ComponentModel.ByteConverter                      oodnW           = new System.ComponentModel.ByteConverter();
     System.Web.UI.WebControls.DetailsViewPageEventArgs       NFia            = new System.Web.UI.WebControls.DetailsViewPageEventArgs(599344366);
     System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNotation Savfrr          = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNotation();
 }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private static Assembly LoadAssemblyFromPackagePath (object sender, ResolveEventArgs args)
    {
      try
      {
        string packagePath = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location);

        string assemblyFilename = args.Name;

        int i = assemblyFilename.IndexOf (',');

        if (i != -1)
        {
          assemblyFilename = assemblyFilename.Substring (0, i);
        }

        string assemblyPath = Path.Combine (packagePath, assemblyFilename + ".dll");

        if (!File.Exists (assemblyPath))
        {
          return null;
        }

        Assembly assembly = Assembly.LoadFrom (assemblyPath);

        return assembly;
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);

        return null;
      }
    }
예제 #22
0
		static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
		{
			//
			if (!args.Name.Contains("SDNSAPI"))
				return null;
			//
			string connectorKeyName = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{33A002DC-D590-4527-B98E-3B9D6F4FC5DC}";
			string connectorLocation = String.Empty;
			//
			if (PInvoke.RegistryHive.HKLM.SubKeyExists_x86(connectorKeyName))
			{
				connectorLocation = PInvoke.RegistryHive.HKLM.GetSubKeyValue_x86(connectorKeyName, "InstallLocation");
			}
			//
			if (String.IsNullOrEmpty(connectorLocation))
			{
				Log.WriteInfo("SimpleDNS API library location is either null or empty");
				return null;
			}
			//
			string assemblyFile = Path.Combine(connectorLocation, args.Name.Split(',')[0] + ".dll");
			//
			Log.WriteInfo(assemblyFile);
			//
			if (!File.Exists(assemblyFile))
			{
				Log.WriteInfo("SimpleDNS API library could not be found or does not exist");
				return null;
			}
			//
			return Assembly.LoadFrom(assemblyFile);
		} 
예제 #23
0
    private System.Reflection.Assembly HandleResolve(object sender, ResolveEventArgs args)
    {
      if (args.Name.StartsWith("FSharp.Core,", StringComparison.OrdinalIgnoreCase))
      {

#if DEBUG
        Logger.TraceInformation("[{0}]: HandleResolve '{1}'", GetType().Name, args.Name);
#endif

        lock (l)
        {
          if (inner)
          {
            return null;
          }

          inner = true;
        }

        try
        {
          return System.Reflection.Assembly.Load("FSharp.Core");
        }
        finally
        {
          lock(l)
          {
            inner = false;
          }
        }
      }

      return null;
    }
예제 #24
0
        public Assembly Resolver(object sender, ResolveEventArgs args)
        {
            lock (this)
            {
                Assembly assembly;
                AssemblyName askedAssembly = new AssemblyName(args.Name);

                string[] fields = args.Name.Split(',');
                string name = fields[0];
                string culture = fields[2];
                // failing to ignore queries for satellite resource assemblies or using [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
                // in AssemblyInfo.cs will crash the program on non en-US based system cultures. detailed discussion: http://connect.microsoft.com/VisualStudio/feedback/details/526836/wpf-appdomain-assemblyresolve-being-called-when-it-shouldnt
                if (name.EndsWith(".resources") && !culture.EndsWith("neutral")) return null;

                string resourceName = string.Format("BlizzTV.Assets.Assemblies.{0}.dll", askedAssembly.Name);
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    if (stream == null)
                    {
                        LogManager.Instance.Write(LogMessageTypes.Fatal, string.Format("Can not resolve asked assembly: {0}", askedAssembly));
                        MessageBox.Show(i18n.CanNotLoadRequiredAssembliesMessage, i18n.CanNotLoadRequiredAssembliesTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(-1);
                    }

                    byte[] assemblyData = new byte[stream.Length];
                    stream.Read(assemblyData, 0, assemblyData.Length);
                    assembly = Assembly.Load(assemblyData);
                }

                LogManager.Instance.Write(LogMessageTypes.Trace, "Loaded embedded assembly: " + askedAssembly);

                return assembly;
            }
        }
예제 #25
0
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            //This handler is called only when the common language runtime tries to bind to the assembly and fails.

            //Retrieve the list of referenced assemblies in an array of AssemblyName.
            Assembly MyAssembly, objExecutingAssemblies;
            string strTempAssmbPath = "";

            objExecutingAssemblies = Assembly.GetExecutingAssembly();
            AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();

            //Loop through the array of referenced assembly names.
            foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
            {
                //Check for the assembly names that have raised the "AssemblyResolve" event.
                if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
                {
                    //Build the path of the assembly from where it has to be loaded.				
                    strTempAssmbPath = Util.GetRalativePath(@"cef\" + args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll");
                    break;
                }

            }
            //Load the assembly from the specified path. 					
            MyAssembly = Assembly.LoadFrom(strTempAssmbPath);

            //Return the loaded assembly.
            return MyAssembly;
        }
예제 #26
0
			Assembly ResolveAssembly(object sender, ResolveEventArgs args)
			{
				var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
				var modulesDirectory = Path.Combine(appDirectory, "Modules");
				var filename = Path.Combine(modulesDirectory, new AssemblyName(args.Name).Name + ".dll");
				return Assembly.Load(File.ReadAllBytes(filename));
			}
		public System.Reflection.Assembly Resolve (object sender, ResolveEventArgs args)
		{
			var location = parent.GetAssemblyPath (args.Name);
			if (location != null)
				return System.Reflection.Assembly.LoadFrom (location);
			return null;
		}
예제 #28
0
파일: Program.cs 프로젝트: gwupe/Gwupe
        private static Assembly EmbeddedAssemblyResolver(object sender, ResolveEventArgs args)
        {
            try
            {
                var assemblyName = new AssemblyName(args.Name);
                String resourceName = Assembly.GetExecutingAssembly().FullName.Split(',').First() + "." + assemblyName.Name + ".dll";
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    if (stream != null)
                    {
                        Byte[] assemblyData = new Byte[stream.Length];
                        stream.Read(assemblyData, 0, assemblyData.Length);
                        if (Array.Exists(UnmanagedAssemblies, element => element.Equals(assemblyName.Name)))
                        {
                            String tempFile = Path.GetTempFileName();
                            File.WriteAllBytes(tempFile, assemblyData);
                            Console.WriteLine("[" + Thread.CurrentThread.ManagedThreadId + "-" + Thread.CurrentThread.Name + "] Loading assembly " + assemblyName.Name + " from " + tempFile);
                            return Assembly.LoadFile(tempFile);
                        }
                        else
                        {
                            return Assembly.Load(assemblyData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message + (ex.InnerException != null ? " : " + ex.InnerException.Message : ""), "Program Failed to access Assembly " + args.Name,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return null;
        }
예제 #29
0
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     
     String s = args.Name.Substring(0,args.Name.IndexOf(",")) + ".dll";
     Console.WriteLine(s);
     return Assembly.LoadFile(s);
 }
예제 #30
0
        private Assembly OrigoDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                Assembly assembly = Assembly.Load(args.Name);
                if (assembly != null)
                    return assembly;
            }
            catch
            {
                // ignore load error
            }

            // *** Try to load by filename - split out the filename of the full assembly name
            // *** and append the base path of the original assembly (ie. look in the same dir)
            // *** NOTE: this doesn't account for special search paths but then that never
            //           worked before either.
            string[] parts = args.Name.Split(',');
            string file = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + parts[0].Trim() +
                          ".dll";
            if (File.Exists(file))
            {
                return Assembly.LoadFrom(file);
            }

            return null;
        }
예제 #31
0
 Assembly AssemblyResolve(object sender, ResolveEventArgs args)
 {
     // this should only be called to resolve OnlineVideos.dll -> return it regardless of the version, only the name "OnlineVideos"
     AssemblyName an = new AssemblyName(args.Name);
     var asm = (sender as AppDomain).GetAssemblies().FirstOrDefault(a => a.GetName().Name == an.Name);
     return asm;
 }
예제 #32
0
        public Assembly OnExecuted(object sender, System.ResolveEventArgs e)
        {
            Trace.TraceInformation("End " + e.Name);
            if (!(e.Name.Contains("Reader") || e.Name.Contains("DataContext")) && !KeepConnected)
            {
                CloseConnection();
            }

            return(null);
        }
 private static System.Reflection.Assembly CustomResolve(object sender, System.ResolveEventArgs args)
 {
     if (args.Name.StartsWith("SharpSVN"))
     {
         var fileName = Path.GetFullPath(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") + args.Name);
         if (File.Exists(fileName))
         {
             return(System.Reflection.Assembly.LoadFile(fileName));
         }
     }
     return(null);
 }
예제 #34
0
        private static Assembly ResolveRhinoCommon(object sender, s.ResolveEventArgs args)
        {
            var name = args.Name;

            if (!name.StartsWith("RhinoCommon"))
            {
                return(null);
            }

            var path = s.IO.Path.Combine(systemDir, "RhinoCommon.dll");

            return(Assembly.LoadFrom(path));
        }
        /// Will attempt to load missing assembly from either x86 or x64 subdir
        internal static System.Reflection.Assembly Resolver(object sender, System.ResolveEventArgs args)
        {
            string assembly_name = new AssemblyName(args.Name).Name + ".dll";

            string resource_path = "AnyCPU.Resources." + Platform() + "." + assembly_name;
            string file_path     = GetInteropDLLPath(assembly_name);

            using (var dll_resource = System.Reflection.Assembly.GetAssembly(typeof(ModuleInitializer)).GetManifestResourceStream(resource_path))
            {
                if (dll_resource == null)
                {
                    return(null);
                }

                if (System.IO.File.Exists(file_path))
                {
                    System.IO.File.Delete(file_path);
                }

                string directory = System.IO.Path.GetDirectoryName(file_path);
                if (!System.IO.Directory.Exists(directory))
                {
                    System.IO.Directory.CreateDirectory(directory);
                }

                using (System.IO.FileStream file_stream = new FileStream(file_path, FileMode.Create))
                {
                    byte[] byte_array = new byte[(int)dll_resource.Length];
                    dll_resource.Read(byte_array, 0, (int)dll_resource.Length);

                    file_stream.Write(byte_array, 0, byte_array.Length);

                    // Since Managed C++ dlls also contained native code, the assembly must be loaded using a LoadFrom!
                    //return Assembly.Load(byte_array);
                }
            }

            Assembly assembly = Assembly.LoadFrom(file_path);

            // Unable to delete file while the assembly is loaded into the domain.
            //File.Delete(file_path);

            return(assembly);
        }
예제 #36
0
            private static SReflection.Assembly AssemblyResolve(object sender, System.ResolveEventArgs args)
            {
                // Ignore missing resources
                if (args.Name.Contains(".resources"))
                {
                    return(null);
                }

                // check for assemblies already loaded
                foreach (SReflection.Assembly assembly in System.AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (assembly.GetName().Name == args.Name)
                    {                           // We had found it. Let's check for a conflict.
                        string asmFile = FindThisGuy(args.Name, false);
                        if (null != asmFile && assembly.Location != asmFile)
                        {
                            LOG.error("Found a duplicated Assembly for {0} on file {1}. This is an error, there can be only one! #highlanderFeelings", args.Name, asmFile);
                        }
                        return(assembly);
                    }
                }

                {
                    string asmFile = FindThisGuy(args.Name, true);
                    if (null != asmFile)
                    {
                        try
                        {
                            LOG.force("Found it on {0}.", asmFile);
                            //return LoadAssemblyByKsp(args.Name, asmFile);
                            return(SReflection.Assembly.LoadFrom(asmFile));
                        }
                        catch (System.Exception ex)
                        {
                            LOG.error("Error {0} loading {1} from {2}!", ex.Message, args.Name, asmFile);
                            return(null);
                        }
                    }
                }

                return(null);
            }
예제 #37
0
        /// <summary>
        /// This delegate helps with resolving types and can be used as a eventhandler
        /// for a <see cref="System.AppDomain.AssemblyResolve"/> event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The event data with information about the type.</param>
        /// <returns>A reference to the assembly where the type is located.</returns>
        /// <remarks>
        /// Use this handler when reading back types from a serialization stread
        /// saved with an earlier version of this assembly.
        /// </remarks>
        public static Assembly AssemblyResolver(object sender, System.ResolveEventArgs e)
        {
            if (e.Name.StartsWith(DiagramAssembly.Name))
            {
                return(DiagramAssembly.Assembly);
            }
            else
            {
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                for (int n = 0; n < assemblies.Length; n++)
                {
                    if (assemblies[n].GetName().Name == e.Name)
                    {
                        return(assemblies[n]);
                    }
                }
            }

            return(null);
        }
예제 #38
0
 private static Assembly CurrentDomainOnAssemblyResolve(object sender, System.ResolveEventArgs args) => _AssemblyResolve?.Invoke(sender, args);
예제 #39
0
        /// <summary>
        /// Used to resolve assemblies available to the <see cref = "UnitOperationSystem"/>
        /// </summary>
        /// <remarks>
        /// <para>This method resolves the assembly locations for types being created. The priority for locating
        /// assemblies is the current applcation domain, then the Cape-Open directory located in the Common Program
        /// Files environment directory (typically C:\Program Files\Common Files\Cape-Open).</para>
        /// <para></para>
        /// </remarks>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Information about the item to be resolved</param>
        /// <returns>The assembly that resolves the type, assembly, or resource; or null if the assembly cannot be resolved.</returns>
        static public System.Reflection.Assembly MyResolveEventHandler(Object sender, System.ResolveEventArgs args)
        {
            System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (System.Reflection.Assembly assembly in assemblies)
            {
                if (args.Name == assembly.FullName)
                {
                    return(assembly);
                }
            }
            string path = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\\Cape-Open";

            return(SearchPathForAssemblies(path, args.Name));
        }
예제 #40
0
 static System.Reflection.Assembly MyResolveEventHandler(Object sender, System.ResolveEventArgs args)
 {
     return(typeof(CapeObjectBase).Assembly);
 }
예제 #41
0
 public Assembly OnExecuting(object sender, System.ResolveEventArgs e)
 {
     Trace.TraceInformation("Begin " + e.Name);
     return(null);
 }
 private void ResolveEventHandler(object esnder, ResolveEventArgs args)
 {
 }
예제 #43
0
        public static Assembly ResolveAssembly(object sender, System.ResolveEventArgs args)
        {
            if (args == null || string.IsNullOrEmpty(args.Name))
            {
                Kohl.Framework.Logging.Log.Warn("Assembly to be loaded can't be reflected.");
                return(null);
            }

            lock (locker)
            {
                string[] fields  = args.Name.Split(',');
                string   name    = fields[0];
                string   culture = fields[2];
                // failing to ignore queries for satellite resource assemblies or using [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
                // in AssemblyInfo.cs will crash the program on non en-US based system cultures.
                if (name.EndsWith(".resources") && !culture.EndsWith("neutral"))
                {
                    return(null);
                }

                // Serialization assemblies - can be ignored - not yet loaded
                if (name == "mscorlib.XmlSerializers" || name == "Terminals.Configuration.XmlSerializers")
                {
                    return(null);
                }

                /* find all dlls from all directories */
                string[] dlls = System.IO.Directory.GetFiles(Kohl.Framework.Info.AssemblyInfo.Directory, "*.dll", System.IO.SearchOption.AllDirectories);

                for (int i = 0; i < dlls.Length; i++)
                {
                    try
                    {
                        string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(dlls[i]);

                        // Load only the file specified in the function argument - if the filename received from Directory::GetFiles() doesn't match the
                        // argument check the next dll until we find the one needed to be loaded dynamically
                        if (fileNameWithoutExtension != args.Name.Split(',')[0])
                        {
                            continue;
                        }

                        // Load the file into the application's working set
                        //Assembly asm = Assembly.LoadFile(dlls[i]);
                        Assembly asm = Assembly.LoadFrom(dlls[i]);

                        // The dll has been found - return the assembly
                        if (asm.FullName == args.Name)
                        {
                            Kohl.Framework.Logging.Log.Info("Dynamically resolved assembly '" + args.Name + "'.");
                            return(asm);
                        }
                    }
                    catch (Exception ex)
                    {
                        Kohl.Framework.Logging.Log.Error("Error loading " + args.Name, ex);
                    }
                }

                string requestingAssembly = args.RequestingAssembly == null ? "-" : args.RequestingAssembly.FullName;

                Kohl.Framework.Logging.Log.Debug("Error resolving " + args.Name + ", requesting assembly: " + requestingAssembly);

                return(null);
            }
        }
예제 #44
0
 private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, System.ResolveEventArgs args)
 {
     return(DependencyResolver.ResolveAssembly(sender, args));
 }
예제 #45
0
 // workaround MS.NET bugs with some specific value / generic types hierarchy
 private Assembly resolve_hack(object _, System.ResolveEventArgs __)
 {
     //Message.Debug ($ "resolve_hack: $(args.Name)");
     return _assembly_builder;
 }
예제 #46
0
파일: Bootstrapper.cs 프로젝트: mh52/P4.net
        //**************************************************
        //* Private
        //**************************************************

        //-------------------------------------------------
        /// <summary>
        /// Custom assembly resolve implementation that
        /// recognizes requests for 'p4dn' assemblies.
        /// </summary>
        private static Assembly CustomResolve(object sender, System.ResolveEventArgs args)
        {
            const string p4DnName = "p4dn";

            if (null != args && null != args.Name && args.Name.StartsWith(p4DnName, StringComparison.OrdinalIgnoreCase))
            {
                if (null == Bootstrapper._p4DnAssembly) // CLR guarantees proper access to volatile reference by multiple threads
                {
                    lock (Bootstrapper.Sync)
                    {
                        if (null == Bootstrapper._p4DnAssembly) // just to be sure, recheck the assembly reference after the memory barrier issued by the lock above
                        {
                            // determine target assembly name
                            var targetDirectory = Path.Combine(
                                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                Path.Combine(
                                    "Perforce",
                                    "P4.NET"));
                            var architecture            = (IntPtr.Size == 4 ? "x86" : "x64").ToLowerInvariant();
                            var thisAssembly            = typeof(Bootstrapper).Assembly;
                            var thisAssemblyFileVersion = FileVersionInfo.GetVersionInfo(thisAssembly.Location).FileVersion;
                            var targetFileName          = Path.Combine(
                                targetDirectory,
                                string.Concat(
                                    ClrSpec,
                                    ".",
                                    BuildSpec,
                                    ".",
                                    thisAssemblyFileVersion,
                                    ".",
                                    architecture,
                                    ".",
                                    p4DnName,
                                    ".dll"));

                            // if needed (target file does not exist or older than this assembly),
                            // extract embedded resources to target directory now
                            var targetFileInfo = new FileInfo(targetFileName);
                            if (!targetFileInfo.Exists)
                            {
                                if (!Directory.Exists(targetDirectory))
                                {
                                    Directory.CreateDirectory(targetDirectory);
                                }

                                const int bufferSize = 0x10000; // 64k
                                var       buffer     = new byte[bufferSize];
                                foreach (var resourceName in thisAssembly.GetManifestResourceNames())
                                {
                                    const string bootstrapperPrefix = @"P4API.Bootstrapper.";
                                    if (resourceName.StartsWith(bootstrapperPrefix, StringComparison.OrdinalIgnoreCase))
                                    {
                                        var extractName = Path.Combine(
                                            targetDirectory,
                                            resourceName
                                            .Substring(bootstrapperPrefix.Length)
                                            .Replace(@"framework", ClrSpec)
                                            .Replace(@"build", BuildSpec)
                                            .Replace(@"version", thisAssemblyFileVersion));
                                        using (var readStream = thisAssembly.GetManifestResourceStream(resourceName))
                                        {
                                            if (null == readStream)
                                            {
                                                throw new InvalidOperationException("Unable to GetManifestResourceStream for one of Assembly.GetManifestResourceNames values");
                                            }
                                            using (var writeStream = File.Create(extractName, bufferSize))
                                            {
                                                int read;
                                                while (0 != (read = readStream.Read(buffer, 0, bufferSize)))
                                                {
                                                    writeStream.Write(buffer, 0, read);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            // load the target file as assembly
                            Bootstrapper._p4DnAssembly = Assembly.LoadFile(targetFileName);
                        }
                    }
                }

                // make sure we can satisfy the requested reference with the embedded assembly (now extracted)
                var reference = new AssemblyName(args.Name);
                if (AssemblyName.ReferenceMatchesDefinition(reference, Bootstrapper._p4DnAssembly.GetName()))
                {
                    return(Bootstrapper._p4DnAssembly);
                }
            }

            // we don't recognize the requested reference
            return(null);
        }