Ejemplo n.º 1
0
        internal InstallationInfo(string path)
        {
            Path      = path;
            Installed = File.Exists(InstallationManager.GetDebuggerVisualizerFilePath(path));

            if (!Installed)
            {
                return;
            }

            // Trying to determine the version by loading it into a sandbox domain.
            try
            {
#if NETFRAMEWORK
                Evidence  evidence      = new Evidence(AppDomain.CurrentDomain.Evidence);
                AppDomain sandboxDomain = AppDomain.CreateDomain(nameof(InitializerSandbox), evidence, Files.GetExecutingPath(), null, false);
                try
                {
                    // initializing by the constructor rather than unwrapping and calling a public method because unwrap may fail if executed from a Visual Studio package
#if NET35
                    Activator.CreateInstance(sandboxDomain, Assembly.GetExecutingAssembly().FullName, typeof(InitializerSandbox).FullName, false, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this, path }, null, null, evidence);
#else
                    Activator.CreateInstance(sandboxDomain, Assembly.GetExecutingAssembly().FullName, typeof(InitializerSandbox).FullName, false, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this, path }, null, null);
#endif
                }
                finally
                {
                    AppDomain.Unload(sandboxDomain);
                }
#else
                var context = new SandboxContext(path);
                try
                {
                    // note: we use LoadFromStream instead of LoadFromAssemblyPath because that keeps the file locked even after unloading the context
                    using var fs = File.OpenRead(InstallationManager.GetDebuggerVisualizerFilePath(path));
                    Assembly asm = context.LoadFromStream(fs);
                    Version         = asm.GetName().Version;
                    RuntimeVersion  = asm.ImageRuntimeVersion;
                    TargetFramework = (Attribute.GetCustomAttribute(asm, typeof(TargetFrameworkAttribute)) as TargetFrameworkAttribute)?.FrameworkName;
                }
                catch (Exception e) when(!e.IsCritical())
                {
                    Version        = null;
                    RuntimeVersion = null;
                }
                finally
                {
                    context.Unload();
                }
#endif
            }
            catch (Exception e) when(!e.IsCritical())
            {
                RuntimeVersion = null;
                InitializeInfoByFileVersion(path);
            }
        }
Ejemplo n.º 2
0
 private void InitializeInfoByFileVersion(string path)
 {
     try
     {
         Version = new Version(FileVersionInfo.GetVersionInfo(InstallationManager.GetDebuggerVisualizerFilePath(path)).FileVersion);
     }
     catch (Exception e) when(!e.IsCritical())
     {
         Version = null;
     }
 }
Ejemplo n.º 3
0
            public InitializerSandbox(InstallationInfo info, string path)
            {
                try
                {
                    Assembly asm = Assembly.LoadFrom(InstallationManager.GetDebuggerVisualizerFilePath(path));
                    info.Version        = asm.GetName().Version;
                    info.RuntimeVersion = asm.ImageRuntimeVersion;
#if !NET35
                    info.TargetFramework = (Attribute.GetCustomAttribute(asm, typeof(TargetFrameworkAttribute)) as TargetFrameworkAttribute)?.FrameworkName;
#endif
                }
                catch (Exception e) when(!e.IsCritical())
                {
                    info.Version        = null;
                    info.RuntimeVersion = null;
                }
            }