我在dll中有这个接口(此代码在元数据中显示在Visual Studio中):
#region Assembly XCapture.dll, v2.0.50727
// d:\svn\dashboard\trunk\Source\MockDiagnosticsServer\lib\XCapture.dll
#endregion
using System;
using System.Runtime.InteropServices;
namespace XCapture
{
[TypeLibType(4160)]
[Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
public interface IDiagnostics
{
[DispId(1)]
void GetStatusInfo(int index, ref object data);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我用这样的类创建了一个COM服务器:
[ComVisible(true)]
[Guid(SimpleDiagnosticsMock.CLSID)]
[ComDefaultInterface(typeof(IDiagnostics))]
[ClassInterface(ClassInterfaceType.None)]
public class SimpleDiagnosticsMock : ReferenceCountedObject, IDiagnostics
{
public const string CLSID = "281C897B-A81F-4C61-8472-79B61B99A6BC";
// These routines perform the additional COM registration needed by
// the service. ---- stripped from example
void IDiagnostics.GetStatusInfo(int index, ref object data)
{
Log.Info("GetStatusInfo called with index={0}, data={1}", index, data); …Run Code Online (Sandbox Code Playgroud) 我肯定在这里遗漏了一些重要的细节.我只是不能使.NET的XPath与Visual Studio项目文件一起工作.
我们加载一个xml文档:
var doc = new XmlDocument();
doc.Load("blah/blah.csproj");
Run Code Online (Sandbox Code Playgroud)
现在执行我的查询:
var nodes = doc.SelectNodes("//ItemGroup");
Console.WriteLine(nodes.Count); // whoops, zero
Run Code Online (Sandbox Code Playgroud)
当然,文件中有名为ItemGroup的节点.此外,此查询有效:
var nodes = doc.SelectNodes("//*/@Include");
Console.WriteLine(nodes.Count); // found some
Run Code Online (Sandbox Code Playgroud)
使用其他文档,XPath工作得很好.我对此完全感到困惑.有人能解释我发生了什么吗?