开发者

Access route not found when trying to call a file added in my solution explorer

public class Hero
{

    XPathNavigator 开发者_运维问答Navigator;
    XPathDocument HeroInformation;        

    public string GetHeroIcon(string Name)
    {            
        XDocument HeroInformation = XDocument.Load("InformationRepositories/HeroRepository/HeroInformation.xml");
        return HeroInformation.Descendants(Name).Single().Element("Icon").Value;
        //return doc.Descendants(name).Single().Element("Icon").Value;
    }

}

I get an error in the first line of my method. I don't understand why it's not working when the adress is clearly written correctly. I'm so confused with this.

Here's a picture of my solution explorer:

Access route not found when trying to call a file added in my solution explorer


your XDocument.Load() method has seeems to search for the requested file in the Bin/debug folder. you need do this to find the check the file at correct location.

XDocument HeroInformation = XDocument.Load("../../InformationRepositories/HeroRepository/HeroInformation.xml");


When your application executes, it is executing from either the bin/Debug or bin/Release directory by default. The path you are trying to follow starts at those directories. You can use the full qualifying path or copy the file/folder structure into the Debug/Release directory. You can also set your application to compile to a different directory. Environment.CurrentDirectory will get you the directory you are executing from, and from there you can use Path.Combine to figure out the location you are looking for the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜