代码之家  ›  专栏  ›  技术社区  ›  Yosi

无效的程序集XML文件

  •  0
  • Yosi  · 技术社区  · 14 年前



    Type classType=类型(点);

            string documentationFileLocation = classType.Assembly.CodeBase;
            if ( !string.IsNullOrEmpty(documentationFileLocation) && documentationFileLocation.StartsWith("file:///") )
            {
                documentationFileLocation = documentationFileLocation.Replace(".exe",".xml");
                documentationFileLocation = documentationFileLocation.Replace("file:///","");
                if(File.Exists(documentationFileLocation))
                {
    
                    XElement document = XElement.Load(documentationFileLocation);
                    // Some Code Logic Here using LINQ
                }
                else
                {
                    Console.WriteLine("Please Go to Project Properties->Build and check 'XML Documentation file'");
    

    我在XElement document=XElement.Load(sr)之后有一个LINQ查询,它不起作用,

    XmlException-根级别的数据无效。1号线,位置1。

    我怎么能修好它?

    编辑:稍微更改了代码-刚刚删除了StreamReader

    2 回复  |  直到 14 年前
        1
  •  1
  •   Lucero    14 年前

    你试过了吗 XDocument.Load() XElement ? 如果文件以XML声明开头 <?xml ...

    编辑:粘贴到pastebin上的文件未指定编码。你能试着在记事本中打开这个文件并将其重新保存为ANSI文件吗?只是为了确保我们没有编码或BOM问题。

        2
  •  2
  •   Jon Skeet    14 年前

    好吧,听起来它只是不是一个有效的XML文件。

    sr.ReadToEnd() 而不是打电话 XElement.Load ,它看起来像什么?如果尝试将文件加载到XML编辑器中,会发生什么情况?

    顺便说一下,最好用 using 声明而非调用 Dispose StreamReader 如果 Load

    最后,你有什么理由不只是使用 XElement.Load(documentationFileLocation)

    推荐文章