C# 发布应用程序后,在查找数据库和xml文件的路径时出错

C# 发布应用程序后,在查找数据库和xml文件的路径时出错,c#,C#,我有OS XP俄文版,安装程序后显示错误“俄文路径无法读取”-以我的方式解释。有人知道吗?谢谢 public string getDBpath() { string path1 = System.Windows.Forms.Application.StartupPath; string path2 = "safer.sdf"; string path3 = Path.Combine(path1, pa

我有OS XP俄文版,安装程序后显示错误“俄文路径无法读取”-以我的方式解释。有人知道吗?谢谢

public string getDBpath() { string path1 = System.Windows.Forms.Application.StartupPath; string path2 = "safer.sdf"; string path3 = Path.Combine(path1, path2); return path3; } public string getXmlPath() { string path1 = System.Windows.Forms.Application.StartupPath; string path2 = @"data/fp.xml"; string path3 = Path.Combine(path1, path2); return path3; } public string getXmlPathTxt() { string path1 = System.Windows.Forms.Application.StartupPath; string path2 = @"data/xml_data.txt"; string path3 = Path.Combine(path1, path2); return path3; } 公共字符串getDBpath(){ 字符串path1=System.Windows.Forms.Application.StartupPath; string path2=“safe.sdf”; 字符串path3=Path.Combine(路径1,路径2); 返回路径3; } 公共字符串getXmlPath(){ 字符串path1=System.Windows.Forms.Application.StartupPath; 字符串路径2=@“data/fp.xml”; 字符串path3=Path.Combine(路径1,路径2); 返回路径3; } 公共字符串getXmlPathTxt(){ 字符串path1=System.Windows.Forms.Application.StartupPath; 字符串路径2=@“data/xml_data.txt”; 字符串path3=Path.Combine(路径1,路径2); 返回路径3; }
不确定这是否能解决问题,但您可以尝试将
System.Windows.Forms.Application.StartupPath
更改为
Assembly.getExecutionGassembly().Location
,看看是否能解决问题

public string getDBpath() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 = "safer.sdf";
            string path3 = Path.Combine(path1, path2);
            return path3;

        }

        public string getXmlPath() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 =  @"data/fp.xml";
            string path3 = Path.Combine(path1, path2);
            return path3;
        }

        public string getXmlPathTxt() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 = @"data/xml_data.txt";
            string path3 = Path.Combine(path1, path2);
            return path3;
        }

您可以尝试使用
Thread.GetDomain().BaseDirectory
而不是
System.Windows.Forms.Application.StartupPath


如果这不起作用,我建议您附加到应用程序的已部署版本。因此,您可以轻松添加
Debugger.Launch()就在创建路径之前。

没问题,我想知道这是否与部署时GAC中的某些内容有关,因此GetExecutionGassembly.Location将为您提供dll/exe在系统上物理位置的路径。这些方法返回什么,您希望它们返回什么?你能记录这些方法的返回值吗?