C# 不为c解决方案间歇性加载XML文件

C# 不为c解决方案间歇性加载XML文件,c#,xml,visual-studio-2015,vsto,C#,Xml,Visual Studio 2015,Vsto,编辑:附加的屏幕截图显示返回的错误。这是一个目录未找到错误。异常详细信息显示在单词Message之后 我使用Visual Studio 2015编写了一个VSC应用程序。该应用程序在Microsoft Word 2013中运行。我正在使用Word online进行测试 在form load事件中,我运行一些代码来打开并读取两个XML文件。这些文件包含我用来填充组合框的数据。每个XML文件都有一个属性集,其中包含“始终复制” 问题是XML文件有时无法加载。如果我再次运行代码,XML文件将加载。大多

编辑:附加的屏幕截图显示返回的错误。这是一个目录未找到错误。异常详细信息显示在单词Message之后

我使用Visual Studio 2015编写了一个VSC应用程序。该应用程序在Microsoft Word 2013中运行。我正在使用Word online进行测试

在form load事件中,我运行一些代码来打开并读取两个XML文件。这些文件包含我用来填充组合框的数据。每个XML文件都有一个属性集,其中包含“始终复制”

问题是XML文件有时无法加载。如果我再次运行代码,XML文件将加载。大多数情况下,80%没有错误,XML文件按预期运行。其他时候,不加载XML文件

这些xml文件位于项目文件夹中,子文件夹为xmlfiles。这些文件非常小,每个大约2k,元素不超过20行,因此如果出现超时问题,我会感到惊讶

你知道为什么应用程序大部分时间都会加载XML文件,而不是所有时间吗

以下是加载文件的代码:

public void GetBookLanguages()
{
    // This application has a combobox that displays a list of languages Amazon supports.
    // the user can select from this list or enter their own.

    string xmlFile = string.Format(@"xmlfiles\\BookLanguages.xml");

    try
    {
        XDocument xmlDoc = XDocument.Load(xmlFile);
        foreach (var language in xmlDoc.Descendants("item"))
        {
            string id = language.Attribute("id").Value;
            string description = language.Value;
            bookLanguages.Add(new BookLanguageTypes()
            {
                bookLangShortName = id,
                bookLangDescription = description
            });
        }

    }
    catch {
        MessageBox.Show("Warning: Could not load the BookLanguages.xml file that contains a list of " +
    "available languages. This information would normally display in a pick list. You can stil run this program.");
    }
}
以下是相应的XML文件:

<?xml version="1.0" encoding="utf-8" ?>
<Items>
  <item id="en">English (en)</item>
  <item id="de">German (de)</item>
  <item id="fr">French (fr)</item>
  <item id="it">Italian (it)</item>
  <item id="es">Spanish (es)</item>
  <item id="zh">Chinese (zh)</item>
  <item id="ja">Japanese (ja)</item>
  <item id="pt">Portuguese (pt)</item>
  <item id="ru">Russian (ru)</item>
  <item id="nl">Dutch (nl)</item>
</Items>

关于这些XML文件为什么不总是加载的原因,您能提供的任何见解都会很有帮助。

当它不加载时,您会得到messagebox吗?为什么要丢弃异常细节?你是否在某个地方设置了一个断点,其中包含加载文件的条件?对不起,我的错。我本想说明例外情况。下次我会更新这个问题。我知道我漏掉了一些东西:嗨,罗恩,我终于发现了错误并把它写进了帖子。感谢您早些时候的回复。您的屏幕截图显示目录为\\mac\blah。这是一个网络位置。您的服务器和网络驱动器所在的任何位置之间是否可能存在断开连接?我在虚拟机中运行Visual Studio,因此我猜从技术上讲,这是一条网络路径,即使它位于同一台机器上。VS项目/解决方案位于驱动器号上,但VS显然希望以这种方式使用它。进一步检查,VisualStudio似乎有文件的完整路径,但我无法更改,至少使用UI无法更改。有没有关于如何解决这个问题并将其移动到正确的驱动器号的想法?