コード例 #1
0
        private static Assembly LoadAssemblyHelper(string assemblyGivenName, string assemblyPath)
        {
            AssemblyName reference      = new AssemblyName(assemblyGivenName);
            string       str            = reference.Name.ToUpper(CultureInfo.InvariantCulture);
            Assembly     loadedAssembly = (Assembly)_loadedAssembliesHash[str];

            if (loadedAssembly != null)
            {
                if (reference.Version != null)
                {
                    AssemblyName definition = new AssemblyName(loadedAssembly.FullName);
                    if (!AssemblyName.ReferenceMatchesDefinition(reference, definition))
                    {
                        string str2 = reference.ToString();
                        string str3 = definition.ToString();
                        throw new InvalidOperationException(System.Xaml.SR.Get("ParserAssemblyLoadVersionMismatch", new object[] { str2, str3 }));
                    }
                }
                return(loadedAssembly);
            }
            if (string.IsNullOrEmpty(assemblyPath))
            {
                loadedAssembly = SafeSecurityHelper.GetLoadedAssembly(reference);
            }
            if (loadedAssembly == null)
            {
                if (!string.IsNullOrEmpty(assemblyPath))
                {
                    loadedAssembly = Assembly.LoadFile(assemblyPath);
                }
                else
                {
                    try
                    {
                        loadedAssembly = Assembly.Load(assemblyGivenName);
                    }
                    catch (FileNotFoundException)
                    {
                        loadedAssembly = null;
                    }
                }
            }
            if (loadedAssembly != null)
            {
                _loadedAssembliesHash[str] = loadedAssembly;
            }
            return(loadedAssembly);
        }
コード例 #2
0
        private Assembly ResolveAssembly(string assemblyName)
        {
            AssemblyName name           = new AssemblyName(assemblyName);
            Assembly     loadedAssembly = SafeSecurityHelper.GetLoadedAssembly(name);

            if (loadedAssembly != null)
            {
                return(loadedAssembly);
            }
            try
            {
                byte[] publicKeyToken = name.GetPublicKeyToken();
                if (((name.Version != null) || (name.CultureInfo != null)) || (publicKeyToken != null))
                {
                    try
                    {
                        return(Assembly.Load(assemblyName));
                    }
                    catch (Exception exception)
                    {
                        if (CriticalExceptions.IsCriticalException(exception))
                        {
                            throw;
                        }
                        AssemblyName assemblyRef = new AssemblyName(name.Name);
                        if (publicKeyToken != null)
                        {
                            assemblyRef.SetPublicKeyToken(publicKeyToken);
                        }
                        return(Assembly.Load(assemblyRef));
                    }
                }
                return(Assembly.LoadWithPartialName(assemblyName));
            }
            catch (Exception exception2)
            {
                if (CriticalExceptions.IsCriticalException(exception2))
                {
                    throw;
                }
                return(null);
            }
        }