Пример #1
0
        // Builds the list of Dependencies for the Assembly Manifest located in the
        // file ``name''.
        //
        // If ``name'' couldn't be loaded, an exception is thrown as the manifest
        // file doesn't exist or is invalid.  If one of ``names'' dependency's
        // can't be loaded, an exception is not thrown; instead, the
        // IAssemblyInfo object returned will hold exception information.
        //
        internal AssemblyDependencies(string name, LoadAssemblyInfo cai)
        {
            AssemblyRef ar = null;

            m_load = LoadAssembly.CreateLoader(cai);
            try
            {
                Trace.WriteLine("Name: " + name);

                AssemblyName an = m_load.LoadAssemblyName(name);

                Trace.WriteLine("assembly name: " + an.Name);
                Trace.WriteLine("assembly full name: " + an.FullName);

                ar = m_load.LoadAssemblyFrom(an);

                Trace.WriteLine("Successfully loaded assembly.");
            }
            catch (Exception e)
            {
                Trace.WriteLine("m_load.LoadAssemblyFrom threw an exception:\n  " +
                                e.ToString());

                /*
                 * If ``m_load.LoadAssemblyFrom'' throws an exception, we want
                 * our caller to get the exception.  However, since this is
                 * the constructor, we need to clean up any allocated resources --
                 * in this case, the resouces of the LoadAssembly object.
                 */
                m_load.Dispose();
                throw e;
            }

            m_name = ar.FullName;

            IList search = new ArrayList();

            m_alAssemInfo = new ArrayList();

            // Add the top-level object, the Assembly containing the manifest.
            // ``search'' will contain any Assemblies that the added object
            // references.
            m_map.Add(m_name, new AssemblyInfo(ar, search, m_alAssemInfo));

            // Get all referenced Assemblies.
            _traverse(search);
        }
Пример #2
0
        // Create the Assembly in its own AppDOmain.  In doing so, it
        // uses the custom paths (AppBase and Relative)
        // specified by the LoadAssemblyInfo object passed when this
        // object was created.
        internal override AssemblyRef LoadAssemblyFrom(AssemblyName an)
        {
            Trace.WriteLine("Loading a custom assembly for: " + an.FullName);
            String fname = "";

            //String.Format (Localization.FMT_APPDOMAIN_NAME,
            //  an.FullName);
            Trace.WriteLine("  -- Friendly Name of new AppDomain: " + fname);
            AppDomain ad = AppDomain.CreateDomain(
                an.FullName,      // friendlyName
                null,             // securityInfo
                m_info.AppPath(), // appBasePath
                m_info.RelPath(), // relativeSearchPath
                false             // shadowCopyFiles
                );

            m_ads.Add(ad);
            Trace.WriteLine("  -- created AppDomain");

            Type   t     = typeof(AssemblyRef);
            string aname = Assembly.GetExecutingAssembly().FullName;

            Trace.WriteLine("Assembly containing AssemblyRef: " + aname);
            Trace.WriteLine("Type full name: " + t.FullName);
            Trace.WriteLine("Type name: " + t.Name);

            ObjectHandle oh = ad.CreateInstance(
                aname,                                                             // Assembly file name
                t.FullName,                                                        // Type name
                false,                                                             // ignore case
                BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, // binding attributes
                null,                                                              // binder
                null,                                                              // args
                null,                                                              // culture info
                null,                                                              // activation attributes
                Assembly.GetExecutingAssembly().Evidence                           // security attributes
                );

            AssemblyRef ar = (AssemblyRef)oh.Unwrap();

            ar.Load(an);
            return(ar);
        }
        }// Paste

        internal void AddAssembly(AssemInfo asinfo)
        {
            try
            {
                // Let's create a strong name....
                byte[] baPublicKey;

                if (asinfo.PublicKey == null || asinfo.PublicKey.Length == 0)
                {
                    // The codebase is of the form file:///c:\somefile\sdfsf
                    // We need to translate it to a simple path
                    Uri uCodebase = new Uri(asinfo.Codebase);

                    // We need to load the assembly to get this info
                    AssemblyLoader al = new AssemblyLoader();
                    AssemblyRef    ar = al.LoadAssemblyInOtherAppDomainFrom(uCodebase.AbsolutePath);

                    AssemblyName an = ar.GetName();
                    baPublicKey = an.GetPublicKey();
                    al.Finished();
                }
                else
                {
                    baPublicKey = StringToByteArray(asinfo.PublicKey);
                }

                StrongNamePublicKeyBlob       snpkb = new StrongNamePublicKeyBlob(baPublicKey);
                StrongNameMembershipCondition snmc  = new StrongNameMembershipCondition(snpkb, asinfo.Name, null);

                m_pl.AddFullTrustAssembly(snmc);
                SecurityPolicyChanged();
                RefreshData();
                RefreshResultView();
            }
            catch (Exception)
            {
                MessageBox(CResourceStore.GetString("CTrustedAssemblies:TrustAssemFail"),
                           CResourceStore.GetString("CTrustedAssemblies:TrustAssemFailTitle"),
                           MB.ICONEXCLAMATION);
            }
        }// AddAssembly
Пример #4
0
        }// HaveCurrentEvidence

        internal Evidence GetEvidence()
        {
            // If we have a thread that is doing this right now, abort
            // it.
            if (m_tEvidence != null)
            {
                m_tEvidence.Abort();
            }
            try
            {
                AssemblyRef ar = m_al.LoadAssemblyInOtherAppDomainFrom(m_txtFilename.Text);
                Evidence    e  = ar.GetEvidence();
                m_al.Finished();
                m_sEvalAssem = m_txtFilename.Text;
                return(e);
            }
            catch (Exception)
            {
                // Let's see if can can figure out what failed...
                if (File.Exists(m_txtFilename.Text) && !Fusion.isManaged(m_txtFilename.Text))
                {
                    MessageBox(CResourceStore.GetString("isNotManagedCode"),
                               CResourceStore.GetString("isNotManagedCodeTitle"),
                               MB.ICONEXCLAMATION);
                }

                else
                {
                    MessageBox(String.Format(CResourceStore.GetString("CantLoadAssembly"), m_txtFilename.Text),
                               CResourceStore.GetString("CantLoadAssemblyTitle"),
                               MB.ICONEXCLAMATION);
                }
                m_al.Finished();
                return(null);
            }
        } // GetEvidence
Пример #5
0
 internal AssemblyInfo(AssemblyName an, ArrayList alAssemInfo)
 {
     m_name        = an.FullName;
     m_assembly    = null;
     m_alAssemInfo = alAssemInfo;
 }