C# 找不到路径的一部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1152083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:28:10  来源:igfitidea点击:

Could not find a part of the path

c#fileconfig

提问by akif

Hey I'm using the ExeConfigurationFileMapclass's OpenMappedExeConfigurationmethod to open a config file. The config file is used by two programs in the same directory.

嘿,我正在使用ExeConfigurationFileMap类的OpenMappedExeConfiguration方法来打开配置文件。配置文件由同一目录中的两个程序使用。

Everything is working fine on my development machine but when I copied the programs to another machine I get this error while executing the program

在我的开发机器上一切正常,但是当我将程序复制到另一台机器时,我在执行程序时收到此错误

Code not find a part of the path D:\email\email.config

The other program can access the email.config file easily. Everything is one directory but the other program is pointing to the old path in my development machine :(

另一个程序可以轻松访问 email.config 文件。一切都是一个目录,但另一个程序指向我开发机器中的旧路径:(

Here is a portion of the code which throws the Exception

这是引发异常的代码的一部分

class Program
    {
        static readonly string configFileName = "email.config";

        static int Main(string[] args)
        {
            try
            {
                var configMap = new ExeConfigurationFileMap { ExeConfigFilename = configFileName };
                Configuration externalConfig = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 1;
            }
        }
    }

采纳答案by Paolo Tedesco

Have you tried searching your project (configuration files included) for that path? It will be surely written somewhere, you just need to find it...

您是否尝试过在您的项目(包括配置文件)中搜索该路径?它肯定会写在某个地方,你只需要找到它......

EDIT: I understood what your problem is, I'm just saying that the D:\emailpath your program is searching is coming from somewhere in your code orin your configuration files. Just try to search for "D:" in your project; use the find in filescommand in Visual Studio (ctrl + shift + f) and make sure to specify *.*in the "look at this file types" box.

编辑:我明白你的问题是什么,我只是说D:\email你的程序搜索的 路径来自你的代码配置文件中的某个地方。试着在你的项目中搜索“D:”;使用find in filesVisual Studio 中的命令 (ctrl + shift + f) 并确保*.*在“查看此文件类型”框中指定。

SECOND EDIT:

第二次编辑

Nope, I don't have specified the path anywhere neither in my code nor in configuration files.

不,我没有在代码和配置文件中的任何地方指定路径。

If you tried searching for the path as I suggested (please do it if you haven't done it yet) then check the configuration files on the target machine. That path is written somewhere, you juat have to find out where, and for that you must use a tool of some kind (even Windows's file search should do).

如果您尝试按照我的建议搜索路径(如果您还没有搜索,请搜索)然后检查目标机器上的配置文件。该路径写在某处,您必须找出在哪里,为此您必须使用某种工具(即使是 Windows 的文件搜索也应该这样做)。