日期:2014-05-17  浏览次数:20804 次

调试生成的文件改名后运行遇到的问题
调试生成的文件名为WindowsApp.exe
将该文件复制后改名后为MyTools.exe
在不改变调试生成的exe文件名时,WindowsApp.exe运行正常,
但是把它改一个文件名时,MyTools.exe运行到主窗口时没有问题,
但是运行子窗体时,可能调用了什么,就弹出错误提示未能加载文件或程序集“WindowsApp”或它的一个依赖项。系统找不到指定的文件。
然后我将原文件WindowsApp.exe复制MyTools.exe同一目录,则不会弹出那个错误提示。
这是什么原因?

------解决方案--------------------
看了,代码修改起来不算太难:

public static void CreateForm(string filePath,  string strName, string namespaceName, Form MdiParentForm)
        {
            int Index = strName.LastIndexOf(".");
            string formName = strName.Substring(Index + 1);
            if (!ShowChildForm(formName, MdiParentForm))
            {
                string path = namespaceName;
                string name = strName;
                Assembly assembly = Assembly.LoadFrom(filePath);
                Form fr = (Form)assembly.CreateInstance(name);
                fr.MdiParent = MdiParentForm;
                fr.Width = 1040;
                fr.Height = 755;
                fr.FormBorderStyle = FormBorderStyle.None;
                fr.StartPosition = FormStartPosition.Manual;
                fr.Show();
            }
        }

调用的时候

                if (this.TOOLS.SelectedNode.Name == "Work")
                {
                    CreateForm(Application.ExecutablePath,"WindowsApp" + "." + Program.userGroup, "WindowsApp", this);
                }
                else