Exemplo n.º 1
0
    static void Main()
    {
        //<snippet2>
        // Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
        Assembly assem = typeof(App).Assembly;

        Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
                          assem, RuntimeEnvironment.FromGlobalAccessCache(assem));
        //</snippet2>

        //<snippet3>
        // Show the path where the CLR was loaded from.
        Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory());
        //</snippet3>

        //<snippet4>
        // Show the CLR's version number.
        Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion());
        //</snippet4>

        //<snippet5>
        // Show the path of the machine's configuration file.
        Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile);
        //</snippet5>
    }
Exemplo n.º 2
0
            /// <summary>
            /// Determines whether an assembly is installed in the Global
            /// Assembly Cache given its file name or path.
            /// </summary>
            /// <param name="assemblyFile">The name or path of the file that contains the manifest of the assembly.</param>
            /// <returns>
            /// <see langword="true" /> if <paramref name="assemblyFile" /> is
            /// installed in the Global Assembly Cache; otherwise,
            /// <see langword="false" />.
            /// </returns>
            public bool IsAssemblyInGac(string assemblyFile)
            {
                try {
                    AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyFile);
                    // the assembly can't be in the GAC if it has no public key
                    if (assemblyName.GetPublicKeyToken() == null)
                    {
                        return(false);
                    }

                    // load assembly
                    Assembly assembly = Assembly.Load(assemblyName);

                    // tests whether the specified assembly is loaded in the
                    // global assembly cache
                    if (PlatformHelper.IsMono)
                    {
                        // TODO: remove mono specific code when FromGlobalAccessCache
                        // is implemented
                        return(assembly.GlobalAssemblyCache);
                    }
                    else
                    {
                        return(RuntimeEnvironment.FromGlobalAccessCache(assembly));
                    }
                } catch {
                    return(false);
                }
            }
        public void FromGlobalAccessCache()
        {
            Assembly corlib = typeof(int).Assembly;
            // FIXME: This doesn't work when doing make distcheck (probably because the corlib used isn't the GAC)
//			Assert.IsTrue (RuntimeEnvironment.FromGlobalAccessCache (corlib), "corlib");
            Assembly corlib_test = Assembly.GetExecutingAssembly();

            Assert.IsFalse(RuntimeEnvironment.FromGlobalAccessCache(corlib_test), "corlib_test");
        }
Exemplo n.º 4
0
        public void PartialTrust_DenyUnrestricted_Success()
        {
            Assembly corlib = typeof(int).Assembly;

            Assert.IsTrue(RuntimeEnvironment.FromGlobalAccessCache(corlib), "corlib");
            Assembly corlib_test = Assembly.GetExecutingAssembly();

            Assert.IsFalse(RuntimeEnvironment.FromGlobalAccessCache(corlib_test), "corlib_test");
        }
Exemplo n.º 5
0
        public void PartialTrust_DenyUnrestricted_Success()
        {
            Assembly corlib = typeof(int).Assembly;

#if NET_2_0
            Assert.IsTrue(RuntimeEnvironment.FromGlobalAccessCache(corlib), "corlib");
#else
            // note: mscorlib.dll wasn't in the GAC for 1.x
            Assert.IsFalse(RuntimeEnvironment.FromGlobalAccessCache(corlib), "corlib");
#endif
            Assembly corlib_test = Assembly.GetExecutingAssembly();
            Assert.IsFalse(RuntimeEnvironment.FromGlobalAccessCache(corlib_test), "corlib_test");
        }
Exemplo n.º 6
0
            /// <summary>
            /// Determines whether an assembly is installed in the Global
            /// Assembly Cache given its file name or path.
            /// </summary>
            /// <param name="assemblyFile">The name or path of the file that contains the manifest of the assembly.</param>
            /// <returns>
            /// <see langword="true" /> if <paramref name="assemblyFile" /> is
            /// installed in the Global Assembly Cache; otherwise,
            /// <see langword="false" />.
            /// </returns>
            public bool IsAssemblyInGac(string assemblyFile)
            {
                try {
                    AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyFile);
                    // the assembly can't be in the GAC if it has no public key
                    if (assemblyName.GetPublicKeyToken() == null)
                    {
                        return(false);
                    }

                    // load assembly
                    Assembly assembly = Assembly.Load(assemblyName);
                    return(RuntimeEnvironment.FromGlobalAccessCache(assembly));
                } catch {
                    return(false);
                }
            }
Exemplo n.º 7
0
        private bool RegGACAssemblys()
        {
            try
            {
                var dllName = "EasyHook.dll";
                var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
                if (!File.Exists(dllPath))
                {
                    throw new Exception("没有找到Dll文件");
                }
                if (!System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
                {
                    new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
                    Thread.Sleep(100);
                }

                foreach (var item in dlls)
                {
                    dllName = item.dllPath;
                    if (!RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
                    {
                        new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            //dllName = "ClassLibrary1.dll";
            //dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
            //new System.EnterpriseServices.Internal.Publish().GacRemove(dllPath);
            //if (!System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
            //{
            //    new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
            //    Thread.Sleep(100);
            //}

            return(true);
        }
Exemplo n.º 8
0
        private bool RegGACAssembly()
        {
            var dllName = "EasyHook.dll";
            var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);

            if (!RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
            {
                new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
                Thread.Sleep(100);
            }

            dllName = "HookLib.dll";
            dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
            new System.EnterpriseServices.Internal.Publish().GacRemove(dllPath);
            if (!RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
            {
                new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
                Thread.Sleep(100);
            }

            return(true);
        }
 public void FromGlobalAccessCache_Null()
 {
     RuntimeEnvironment.FromGlobalAccessCache(null);
 }