Example #1
0
 /// <summary>
 ///   Select a assembly to load.
 /// </summary>
 /// <param name="sender">
 ///   A <b>object</b> value indicates the event sender.
 /// </param>
 /// <param name="e">
 ///   A <b>EventArgs</b> value indicates the argument.
 /// </param>
 private void OpenAssemblyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // Do open!
     _assembly = Utility.ParseAssembly(Utility.LoadAssemblyFromFile());
     BindingNamespace();
 }
Example #2
0
        /// <summary>
        ///   Load assembly from file.
        /// </summary>
        private void LoadAssemblyFromFile()
        {
            // Openfiledialog.
            using (OpenFileDialog fdOpenAssembly = new OpenFileDialog())
            {
                fdOpenAssembly.Filter = "exe files (*.exe)|*.exe|dll files (*.dll)|*.dll";
                fdOpenAssembly.FilterIndex = 1;
                fdOpenAssembly.RestoreDirectory = true;

                if (fdOpenAssembly.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        string assemblyName = fdOpenAssembly.FileName;
                        string safeName = fdOpenAssembly.SafeFileName;

                        // Get assembly's name.
                        string assemblyShowName = safeName.Substring(0, safeName.Length - 4);

                        // Clear the old tree
                        tvAssembly.Nodes.Clear();

                        // Set tree's root name as assembly's name.
                        TreeNode root = new TreeNode(assemblyShowName);
                        root.Name = "Assembly";
                        tvAssembly.Nodes.Add(root);

                        // Load assembly form file.
                        Assembly assembly = Assembly.LoadFrom(assemblyName);

                        // Ok, but have some other problem, assembly.getTypes() will throw RelectionTypeLoadException.
                        // I'm looking for the reason.
                        // Assembly assembly = Assembly.ReflectionOnlyLoadFrom(assemblyName);
                        // Assembly assembly = Assembly.ReflectionOnlyLoad(assemblyName);

                        _assembly = new GCAAssembly(assembly);

                        // Binding the _assembly to TreeView control.
                        BindingNamespaces();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
            }
        }